//! MinionsEdit.debug.js
//

(function() {

Type.registerNamespace('MinionsEdit.Classes');

////////////////////////////////////////////////////////////////////////////////
// MiProperty

MiProperty = function MiProperty(label, propName) {
    /// <param name="label" type="String">
    /// </param>
    /// <param name="propName" type="String">
    /// </param>
    /// <field name="_propertyCss$2" type="String" static="true">
    /// </field>
    /// <field name="defaultCss" type="Object" static="true">
    /// </field>
    /// <field name="propName" type="String">
    /// </field>
    /// <field name="label" type="String">
    /// </field>
    /// <field name="defaultValue" type="String">
    /// </field>
    /// <field name="event" type="jQueryEvent">
    /// </field>
    /// <field name="target" type="jQueryObject">
    /// </field>
    /// <field name="units" type="String">
    /// </field>
    /// <field name="_page$2" type="MiPropPage">
    /// </field>
    /// <field name="_opacityList$2" type="Array" elementType="Number" elementInteger="true" static="true">
    /// </field>
    /// <field name="_alphaValues$2" type="Object" static="true">
    /// </field>
    MiProperty.initializeBase(this);
    this.label = label;
    this.propName = propName;
    this.element = $("<div class='MiProperty'/>");
}
MiProperty.get__opacityList$2 = function MiProperty$get__opacityList$2() {
    /// <value type="Array" elementType="Number" elementInteger="true"></value>
    if (MiProperty._opacityList$2 == null) {
        MiProperty._opacityList$2 = new Array(101);
        for (var i = 0; i < 101; i++) {
            MiProperty._opacityList$2[i] = i;
        }
    }
    return MiProperty._opacityList$2;
}
MiProperty.get_alphaValues = function MiProperty$get_alphaValues() {
    /// <value type="Object"></value>
    if (MiProperty._alphaValues$2 == null) {
        MiProperty._alphaValues$2 = {};
        var $enum1 = ss.IEnumerator.getEnumerator(MiProperty.get__opacityList$2());
        while ($enum1.moveNext()) {
            var i = $enum1.current;
            MiProperty._alphaValues$2[i.toString()] = (i / 100).toString();
        }
    }
    return MiProperty._alphaValues$2;
}
MiProperty.colorPickerTable = function MiProperty$colorPickerTable(label) {
    /// <param name="label" type="String">
    /// </param>
    /// <returns type="jQueryObject"></returns>
    var ot = '';
    ot += "<div class='MiColorPicker'>";
    ot += '<div>' + label + ' ';
    ot += "<span class='Transparent' title='none'>x</span>";
    ot += "<span class='Transparent' title='transparent'>&#9744;</span>";
    ot += '</div>';
    ot += MinionsEdit.Classes.MiColorPicker.html;
    ot += '</div>';
    return $(ot).css({ width: 16 * 7 });
}
MiProperty.dictOf = function MiProperty$dictOf(st, en) {
    /// <param name="st" type="Number" integer="true">
    /// </param>
    /// <param name="en" type="Number" integer="true">
    /// </param>
    /// <returns type="Object"></returns>
    var d = {};
    for (var i = st; i <= en; i++) {
        d[i.toString()] = i.toString();
    }
    return d;
}
MiProperty.prototype = {
    propName: null,
    label: null,
    defaultValue: null,
    event: null,
    target: null,
    units: null,
    _page$2: null,
    
    getLive: function MiProperty$getLive(propName, deef) {
        /// <param name="propName" type="String">
        /// </param>
        /// <param name="deef" type="String">
        /// </param>
        /// <returns type="String"></returns>
        var v = deef;
        new Nsb.Classes.Evo().setValue(propName, null).evoke(ss.Delegate.create(MinionEdit.get_activeFocus(), MinionEdit.get_activeFocus().getCss)).response(function(evo) {
            v = evo.value || v;
        }).fire();
        return v;
    },
    
    setLive: function MiProperty$setLive(propName, value) {
        /// <param name="propName" type="String">
        /// </param>
        /// <param name="value" type="String">
        /// </param>
        new Nsb.Classes.Evo().setValue(propName, value).evoke(ss.Delegate.create(MinionEdit.get_activeFocus(), MinionEdit.get_activeFocus().setCss)).fire();
        this.queSave();
    },
    
    get_widgetValue: function MiProperty$get_widgetValue() {
        /// <summary>
        /// Gets or sets the widget value.
        /// </summary>
        /// <value type="String"></value>
        throw new Error('Must be overriden');
    },
    set_widgetValue: function MiProperty$set_widgetValue(value) {
        /// <summary>
        /// Gets or sets the widget value.
        /// </summary>
        /// <value type="String"></value>
        return value;
    },
    
    get_liveValue: function MiProperty$get_liveValue() {
        /// <value type="String"></value>
        var tmpValue = '';
        new Nsb.Classes.Evo().setValue(this.propName, null).evoke(ss.Delegate.create(MinionEdit.get_activeFocus(), MinionEdit.get_activeFocus().getCss)).response(ss.Delegate.create(this, function(evo) {
            this.set_widgetValue(tmpValue = evo.value);
        })).fire();
        return tmpValue;
    },
    set_liveValue: function MiProperty$set_liveValue(value) {
        /// <value type="String"></value>
        new Nsb.Classes.Evo().setValue(this.propName, value).evoke(ss.Delegate.create(MinionEdit.get_activeFocus(), MinionEdit.get_activeFocus().setCss)).fire();
        this.set_widgetValue(this.get_liveValue());
        this.queSave();
        return value;
    },
    
    initialize: function MiProperty$initialize(page) {
        /// <param name="page" type="MiPropPage">
        /// </param>
        /// <returns type="MiProperty"></returns>
        this._page$2 = page;
        this.element.appendTo(this._page$2.element);
        this.units = this.units || page.get_units();
        page.addProp(this.label, this);
        this._endBuild$2();
        return this;
    },
    
    _endBuild$2: function MiProperty$_endBuild$2() {
        var x = this.get_liveValue();
    },
    
    setDefault: function MiProperty$setDefault(deef) {
        /// <param name="deef" type="String">
        /// </param>
        /// <returns type="MiProperty"></returns>
        this.defaultValue = deef;
        return this;
    },
    
    setUnits: function MiProperty$setUnits(units) {
        /// <param name="units" type="String">
        /// </param>
        /// <returns type="MiProperty"></returns>
        switch (units) {
            case 'autoPt':
                this.units = (MinionEdit.get_activeFocus().get_data().relative) ? '%' : 'pt';
                break;
            default:
                this.units = units;
                break;
        }
        return this;
    },
    
    clickEv: function MiProperty$clickEv(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        this.event = e;
        this.target = $(e.target);
        this.set_liveValue(this.get_widgetValue());
    },
    
    triggerUpdate: function MiProperty$triggerUpdate(label) {
        /// <param name="label" type="String">
        /// </param>
        var prop = this._page$2.getProp(label);
        if (prop != null) {
            prop.update();
        }
    },
    
    update: function MiProperty$update() {
        this.set_widgetValue(this.get_liveValue());
    },
    
    queSave: function MiProperty$queSave() {
        this._page$2.queSave();
    }
}


////////////////////////////////////////////////////////////////////////////////
// MinionsEdit.Classes._miWidgetCss

MinionsEdit.Classes._miWidgetCss = function MinionsEdit_Classes__miWidgetCss() {
    /// <field name="_widgetCss" type="String" static="true">
    /// </field>
}


////////////////////////////////////////////////////////////////////////////////
// MiEnumWidget

MiEnumWidget = function MiEnumWidget(label, propName, st, en) {
    /// <param name="label" type="String">
    /// </param>
    /// <param name="propName" type="String">
    /// </param>
    /// <param name="st" type="Number" integer="true">
    /// </param>
    /// <param name="en" type="Number" integer="true">
    /// </param>
    MiEnumWidget.initializeBase(this, [ label, propName ]);
    this.element.addClass('MiEPEnum');
    for (var i = st; i <= en; i++) {
        $('<div/>').appendTo(this.element).attr('title', i.toString()).html(i.toString()).click(ss.Delegate.create(this, this.clickEv));
    }
}
MiEnumWidget.prototype = {
    
    get_widgetValue: function MiEnumWidget$get_widgetValue() {
        /// <value type="String"></value>
        return this.target.html() + this.units;
    },
    set_widgetValue: function MiEnumWidget$set_widgetValue(value) {
        /// <value type="String"></value>
        var vn = parseInt(value);
        var v = (isNaN(vn)) ? '0' : vn.toString();
        $('.MiEPBorderSelect', this.element).removeClass('MiEPBorderSelect');
        this.element.find("div[title='" + v + "']").addClass('MiEPBorderSelect');
        return value;
    }
}


////////////////////////////////////////////////////////////////////////////////
// MiSelectWidget

MiSelectWidget = function MiSelectWidget(label, propName, values) {
    /// <param name="label" type="String">
    /// </param>
    /// <param name="propName" type="String">
    /// </param>
    /// <param name="values" type="Object">
    /// </param>
    /// <field name="_sel" type="jQueryObject">
    /// </field>
    /// <field name="_values" type="Object">
    /// </field>
    MiSelectWidget.initializeBase(this, [ label, propName ]);
    this._values = values;
    this.defaultValue = Object.keys(values)[0];
    this.element.addClass('MiEPSelect');
    var el = $('<div/>').appendTo(this.element);
    this._sel = $('<select/>').appendTo(el).change(ss.Delegate.create(this, this.clickEv));
    $('<span/>').appendTo(el).html(label);
    var $dict1 = values;
    for (var $key2 in $dict1) {
        var pair = { key: $key2, value: $dict1[$key2] };
        $('<option/>').appendTo(this._sel).attr('value', pair.value).html(pair.key);
    }
}
MiSelectWidget.prototype = {
    _sel: null,
    _values: null,
    
    get_widgetValue: function MiSelectWidget$get_widgetValue() {
        /// <value type="String"></value>
        var v = this._sel.val();
        return (v === 'none') ? 'remove' : v;
    },
    set_widgetValue: function MiSelectWidget$set_widgetValue(value) {
        /// <value type="String"></value>
        this._sel.val(value || this._values[this.defaultValue]);
        return value;
    }
}


////////////////////////////////////////////////////////////////////////////////
// MiColorWidget

MiColorWidget = function MiColorWidget(label, propName) {
    /// <param name="label" type="String">
    /// </param>
    /// <param name="propName" type="String">
    /// </param>
    MiColorWidget.initializeBase(this, [ label, propName ]);
    this.element.append(MiProperty.colorPickerTable(label).addClass('MiEPProp').click(ss.Delegate.create(this, this.clickEv)));
}
MiColorWidget.prototype = {
    
    get_widgetValue: function MiColorWidget$get_widgetValue() {
        /// <value type="String"></value>
        var el = $(this.event.target);
        var color = el.attr('title');
        return (color === 'none') ? 'remove' : color;
    },
    
    initialize: function MiColorWidget$initialize(page) {
        /// <param name="page" type="MiPropPage">
        /// </param>
        /// <returns type="MiProperty"></returns>
        MiColorWidget.callBaseMethod(this, 'initialize', [ page ]);
        this.element.append(new MiAlphaWidget('Opacity', this.propName).setDefault('1').initialize(page).element);
        return this;
    }
}


////////////////////////////////////////////////////////////////////////////////
// MiBorderWidthWidget

MiBorderWidthWidget = function MiBorderWidthWidget(label, propName, st, en) {
    /// <param name="label" type="String">
    /// </param>
    /// <param name="propName" type="String">
    /// </param>
    /// <param name="st" type="Number" integer="true">
    /// </param>
    /// <param name="en" type="Number" integer="true">
    /// </param>
    MiBorderWidthWidget.initializeBase(this, [ label, propName, st, en ]);
}
MiBorderWidthWidget.prototype = {
    
    get_liveValue: function MiBorderWidthWidget$get_liveValue() {
        /// <value type="String"></value>
        return MiBorderWidthWidget.callBaseMethod(this, 'get_liveValue');
    },
    set_liveValue: function MiBorderWidthWidget$set_liveValue(value) {
        /// <value type="String"></value>
        var style = this.getLive('border-style', 'solid');
        style = (style === 'none') ? 'solid' : style;
        var color = this.getLive('border-color', MiProperty.defaultCss['border-color']);
        this.setLive('border-style', ((!!parseInt(value)) ? style : 'none'));
        this.setLive('border-color', color);
        MiBorderWidthWidget.callBaseMethod(this, 'set_liveValue', [ value ]);
        this.triggerUpdate('style');
        return value;
    },
    
    initialize: function MiBorderWidthWidget$initialize(page) {
        /// <param name="page" type="MiPropPage">
        /// </param>
        /// <returns type="MiProperty"></returns>
        this.units = 'px';
        MiBorderWidthWidget.callBaseMethod(this, 'initialize', [ page ]);
        return this;
    }
}


////////////////////////////////////////////////////////////////////////////////
// MiBorderStyleWidget

MiBorderStyleWidget = function MiBorderStyleWidget(label, propName, values) {
    /// <param name="label" type="String">
    /// </param>
    /// <param name="propName" type="String">
    /// </param>
    /// <param name="values" type="Object">
    /// </param>
    MiBorderStyleWidget.initializeBase(this, [ label, propName, values ]);
}
MiBorderStyleWidget.prototype = {
    
    get_liveValue: function MiBorderStyleWidget$get_liveValue() {
        /// <value type="String"></value>
        return MiBorderStyleWidget.callBaseMethod(this, 'get_liveValue');
    },
    set_liveValue: function MiBorderStyleWidget$set_liveValue(value) {
        /// <value type="String"></value>
        MiBorderStyleWidget.callBaseMethod(this, 'set_liveValue', [ value ]);
        this.triggerUpdate('BorderWidth');
        return value;
    }
}


////////////////////////////////////////////////////////////////////////////////
// MiBorderRadius

MiBorderRadius = function MiBorderRadius(label, values) {
    /// <param name="label" type="String">
    /// </param>
    /// <param name="values" type="Object">
    /// </param>
    MiBorderRadius.initializeBase(this, [ label, 'border-radius', values ]);
}
MiBorderRadius.prototype = {
    
    get_liveValue: function MiBorderRadius$get_liveValue() {
        /// <value type="String"></value>
        var v = parseInt(this.getLive('border-radius', '0')).toString();
        this.set_widgetValue(v);
        return v;
    },
    set_liveValue: function MiBorderRadius$set_liveValue(value) {
        /// <value type="String"></value>
        value = value + 'px';
        var d = { '-moz-border-radius': value, '-webkit-border-radius': value, 'border-radius': value };
        this.setLive('all', d);
        this.set_widgetValue(this.get_liveValue());
        return value;
    }
}


////////////////////////////////////////////////////////////////////////////////
// MiAlphaWidget

MiAlphaWidget = function MiAlphaWidget(label, propName) {
    /// <param name="label" type="String">
    /// </param>
    /// <param name="propName" type="String">
    /// </param>
    /// <field name="_color$4" type="String">
    /// </field>
    MiAlphaWidget.initializeBase(this, [ label, propName, MiProperty.get_alphaValues() ]);
    $('select', this.element).after('%&nbsp;');
}
MiAlphaWidget.prototype = {
    _color$4: null,
    
    get_liveValue: function MiAlphaWidget$get_liveValue() {
        /// <value type="String"></value>
        this._color$4 = this.getLive(this.propName, 'rgba(0,0,0,1)');
        this.set_widgetValue(new NColor().parse(this._color$4).alpha.toString());
        return this.get_widgetValue();
    },
    set_liveValue: function MiAlphaWidget$set_liveValue(value) {
        /// <value type="String"></value>
        this._color$4 = this.getLive(this.propName);
        this._color$4 = new NColor().parse(this._color$4).a(parseFloat(this.get_widgetValue())).toRgba();
        new Nsb.Classes.Evo().setValue(this.propName, this._color$4).evoke(ss.Delegate.create(MinionEdit.get_activeFocus(), MinionEdit.get_activeFocus().setCss)).response(ss.Delegate.create(this, function(evo) {
            this.set_widgetValue(new NColor().parse(evo.value).alpha.toString());
        })).fire();
        this.queSave();
        return value;
    }
}


////////////////////////////////////////////////////////////////////////////////
// MiFontSizeWidget

MiFontSizeWidget = function MiFontSizeWidget(label, propName, st, en) {
    /// <param name="label" type="String">
    /// </param>
    /// <param name="propName" type="String">
    /// </param>
    /// <param name="st" type="Number" integer="true">
    /// </param>
    /// <param name="en" type="Number" integer="true">
    /// </param>
    MiFontSizeWidget.initializeBase(this, [ label, propName, st, en ]);
    this.setUnits('autoPt');
}
MiFontSizeWidget.prototype = {
    
    get_widgetValue: function MiFontSizeWidget$get_widgetValue() {
        /// <value type="String"></value>
        return this.target.html();
    },
    set_widgetValue: function MiFontSizeWidget$set_widgetValue(value) {
        /// <value type="String"></value>
        var vn = parseFloat(value);
        var v = (isNaN(vn)) ? 0 : vn;
        vn = Math.round(v);
        $('.MiEPBorderSelect', this.element).removeClass('MiEPBorderSelect');
        this.element.find("div[title='" + vn + "']").addClass('MiEPBorderSelect');
        return value;
    },
    
    get_liveValue: function MiFontSizeWidget$get_liveValue() {
        /// <value type="String"></value>
        var pt = parseFloat(MinionEdit.get_activeFocus().element.css('font-size')) * 0.75;
        var pts = Math.round(pt).toString();
        this.set_widgetValue(pts);
        return pts;
    },
    set_liveValue: function MiFontSizeWidget$set_liveValue(value) {
        /// <value type="String"></value>
        var cv = Minion.pt(MinionEdit.get_activeFocus().element.css('font-size'));
        var cr = Minion.pt(this.getLive('font-size'));
        var nv = parseFloat(value);
        var pts = Math.round(nv / cv * cr * 10) / 10 + 'pt';
        new Nsb.Classes.Evo().setValue(this.propName, pts).evoke(ss.Delegate.create(MinionEdit.get_activeFocus(), MinionEdit.get_activeFocus().setCss)).fire();
        this.set_widgetValue(this.get_liveValue());
        this.queSave();
        return value;
    }
}


////////////////////////////////////////////////////////////////////////////////
// MiPxWidget

MiPxWidget = function MiPxWidget(label, propName, values) {
    /// <param name="label" type="String">
    /// </param>
    /// <param name="propName" type="String">
    /// </param>
    /// <param name="values" type="Object">
    /// </param>
    MiPxWidget.initializeBase(this, [ label, propName, values ]);
}
MiPxWidget.prototype = {
    
    get_widgetValue: function MiPxWidget$get_widgetValue() {
        /// <value type="String"></value>
        var v = this._sel.val();
        return (!parseInt(v)) ? 'remove' : v + 'px';
    },
    set_widgetValue: function MiPxWidget$set_widgetValue(value) {
        /// <value type="String"></value>
        value = parseInt(value).toString();
        this._sel.val(value || '0');
        return value;
    }
}


////////////////////////////////////////////////////////////////////////////////
// MiPropPage

MiPropPage = function MiPropPage(panel, container) {
    /// <param name="panel" type="MiPropPanel">
    /// </param>
    /// <param name="container" type="jQueryObject">
    /// </param>
    /// <field name="_widgetCss$2" type="String" static="true">
    /// </field>
    /// <field name="_container$2" type="jQueryObject">
    /// </field>
    /// <field name="_panel$2" type="MiPropPanel">
    /// </field>
    /// <field name="_widget$2" type="jQueryObject">
    /// </field>
    /// <field name="_allProps$2" type="Object">
    /// </field>
    this._allProps$2 = {};
    MiPropPage.initializeBase(this);
    this._panel$2 = panel;
    this._container$2 = container;
    this.element = $("<div class='MiEPPage'/>").appendTo(this._container$2).show();
    this.newBox();
}
MiPropPage.ev = function MiPropPage$ev(panel, container) {
    /// <param name="panel" type="MiPropPanel">
    /// </param>
    /// <param name="container" type="jQueryObject">
    /// </param>
    /// <returns type="MiPropPage"></returns>
    $('.MiEPPage,.MiEPEnder', container).remove();
    return new MiPropPage(panel, container);
}
MiPropPage.prototype = {
    _container$2: null,
    _panel$2: null,
    _widget$2: null,
    
    get_units: function MiPropPage$get_units() {
        /// <value type="String"></value>
        return this._panel$2.get_units();
    },
    
    append: function MiPropPage$append(prop) {
        /// <param name="prop" type="MiProperty">
        /// </param>
        /// <returns type="MiPropPage"></returns>
        prop.initialize(this);
        this._widget$2.append(prop.element);
        return this;
    },
    
    queSave: function MiPropPage$queSave() {
        this._panel$2.queSave = true;
        Nsb.Classes.Evo.trigger('MaskRubberbandEv', MinionEdit.get_activeFocus());
    },
    
    newBox: function MiPropPage$newBox() {
        /// <returns type="MiPropPage"></returns>
        this._widget$2 = $("<div class='MiEPBox'/>").appendTo(this.element);
        return this;
    },
    
    label: function MiPropPage$label(label) {
        /// <param name="label" type="String">
        /// </param>
        /// <returns type="MiPropPage"></returns>
        $("<div class='MiEPLabel'/>").appendTo(this._widget$2).html(label);
        return this;
    },
    
    boxWidth: function MiPropPage$boxWidth(w) {
        /// <param name="w" type="Number" integer="true">
        /// </param>
        /// <returns type="MiPropPage"></returns>
        this._widget$2.css({ width: w });
        return this;
    },
    
    ender: function MiPropPage$ender() {
        /// <returns type="MiPropPage"></returns>
        this._container$2.append($("<div class='MiEPEnder'/>"));
        return this;
    },
    
    addProp: function MiPropPage$addProp(key, value) {
        /// <param name="key" type="String">
        /// </param>
        /// <param name="value" type="MiProperty">
        /// </param>
        this._allProps$2[key.toLowerCase()] = value;
    },
    
    getProp: function MiPropPage$getProp(key) {
        /// <param name="key" type="String">
        /// </param>
        /// <returns type="MiProperty"></returns>
        return this._allProps$2[key.toLowerCase()];
    }
}


////////////////////////////////////////////////////////////////////////////////
// NColor

NColor = function NColor() {
    /// <field name="alpha" type="Number">
    /// </field>
    /// <field name="blue" type="Number" integer="true">
    /// </field>
    /// <field name="green" type="Number" integer="true">
    /// </field>
    /// <field name="red" type="Number" integer="true">
    /// </field>
}
NColor.prototype = {
    alpha: 1,
    blue: 0,
    green: 0,
    red: 0,
    
    toRgba: function NColor$toRgba() {
        /// <returns type="String"></returns>
        return String.format('rgba({0}, {1}, {2}, {3})', this.red, this.green, this.blue, this.alpha);
    },
    
    toRgb: function NColor$toRgb() {
        /// <returns type="String"></returns>
        return String.format('rgb({0}, {1}, {2})', this.red, this.green, this.blue);
    },
    
    r: function NColor$r(c) {
        /// <param name="c" type="Number" integer="true">
        /// </param>
        /// <returns type="NColor"></returns>
        this.red = c;
        return this;
    },
    
    g: function NColor$g(c) {
        /// <param name="c" type="Number" integer="true">
        /// </param>
        /// <returns type="NColor"></returns>
        this.green = c;
        return this;
    },
    
    b: function NColor$b(c) {
        /// <param name="c" type="Number" integer="true">
        /// </param>
        /// <returns type="NColor"></returns>
        this.blue = c;
        return this;
    },
    
    a: function NColor$a(a) {
        /// <param name="a" type="Number">
        /// </param>
        /// <returns type="NColor"></returns>
        this.alpha = a;
        return this;
    },
    
    parse: function NColor$parse(c) {
        /// <param name="c" type="String">
        /// </param>
        /// <returns type="NColor"></returns>
        c = c.trim();
        var tc = [ '0', '0', '0', '1' ];
        try {
            if (!c.indexOf('rgba')) {
                tc = eval(c.replace(/^rgba\((\d+),\s*(\d+),\s*(\d+),\s*([.\d]+)\)$/, "['$1','$2','$3','$4']"));
            }
            else if (!c.indexOf('rgb')) {
                tc = eval(c.replace(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/, "['$1','$2','$3','1']"));
            }
            else if (!c.indexOf('#')) {
                if (c.length === 7) {
                    tc = eval(c.replace(/^#([\dA-F][\dA-F])([\dA-F][\dA-F])([\dA-F][\dA-F])$/i, "['$1','$2','$3','1']"));
                }
                else if (c.length === 4) {
                    tc = eval(c.replace(/^#([\dA-F])([\dA-F])([\dA-F])$/, "['$1$1','$2$2','$3$3','1']"));
                }
                else if (c.length === 9) {
                    tc = eval(c.replace(/^#([\dA-F][\dA-F])([\dA-F][\dA-F])([\dA-F][\dA-F])([\dA-F][\dA-F])$/i, "['$2','$3','$4','$1']"));
                    tc[3] = (100 / parseInt(tc[3], 16)).toString().substr(0, 4);
                }
                else if (c.length === 5) {
                    tc = eval(c.replace(/^#([\dA-F])([\dA-F])([\dA-F])([\dA-F])$/i, "['$2$2','$3$3','$4$4','$1$1']"));
                    tc[3] = (100 / parseInt(tc[3], 16)).toString().substr(0, 4);
                }
            }
        }
        catch (ex) {
            Inform.debug('Failed to convert color {0} : {1}', c, ex);
        }
        var radix = (c.substr(0, 1) === '#') ? 16 : 10;
        this.red = parseInt(tc[0], radix);
        this.green = parseInt(tc[1], radix);
        this.blue = parseInt(tc[2], radix);
        this.alpha = parseFloat(tc[3]);
        return this;
    }
}


////////////////////////////////////////////////////////////////////////////////
// MinionsEdit.Classes.MiColorPicker

MinionsEdit.Classes.MiColorPicker = function MinionsEdit_Classes_MiColorPicker() {
    /// <field name="pickerCss" type="String" static="true">
    /// </field>
    /// <field name="html" type="String" static="true">
    /// </field>
}


////////////////////////////////////////////////////////////////////////////////
// PanelPopup

PanelPopup = function PanelPopup() {
    /// <field name="_css$3" type="String" static="true">
    /// </field>
    PanelPopup.initializeBase(this);
    Cluster.glass(ss.Delegate.create(this, this.cancelEv));
    this.element = $('<div/>').addClass('PanelPopup AboveHider WhiteGradiant').css({ position: 'absolute' }).appendTo($(document.body));
    $(document).bind('keydown.PanelPopup', ss.Delegate.create(this, this.keysEv));
}
PanelPopup.prototype = {
    
    destroyEv: function PanelPopup$destroyEv(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        this.element.remove();
        Cluster.glassOff(true);
        $(document).unbind('.PanelPopup');
    },
    
    keysEv: function PanelPopup$keysEv(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        if (e.which === 27) {
            this.cancelEv(e);
        }
    },
    
    cancelEv: function PanelPopup$cancelEv(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        Inform.debug('PanelPopup.CancelEv()');
        this.destroyEv(e);
    }
}


////////////////////////////////////////////////////////////////////////////////
// EditProps

EditProps = function EditProps() {
    /// <field name="_full$4" type="Boolean">
    /// </field>
    /// <field name="_src$4" type="Object">
    /// </field>
    EditProps.initializeBase(this);
}
EditProps.prototype = {
    _full$4: false,
    _src$4: null,
    
    editDAw: function EditProps$editDAw(awp, cssD) {
        /// <param name="awp" type="Await">
        /// </param>
        /// <param name="cssD" type="Object">
        /// </param>
        this._src$4 = cssD;
        cssD = cssD.css || cssD;
        var css = { width: '340px', height: '380px' };
        var cssTxt = Rx.prettyJson(cssD || {}, '\t').replace(/^{[\r\n]*|[\r\n]*}$|\t/g, '');
        this.textAreaAw(awp, { Msg: 'Edit minion properties', Value: cssTxt, Css: css, Attr: { wrap: 'off' }, Customize: ss.Delegate.create(this, this._customStuff$4), Verify: ss.Delegate.create(this, function(result) {
            try {
                this._rePkg$4(result);
                this._destroy$4();
                return true;
            }
            catch (ex) {
                alert(String.format('Invalid css : {0}', ex));
                return false;
            }
        }), Complete: ss.Delegate.create(this, function(result) {
            return this._rePkg$4(result);
        }), Finally: ss.Delegate.create(this, this._destroy$4) });
        this._fullEv$4(null);
    },
    
    _rePkg$4: function EditProps$_rePkg$4(txt) {
        /// <param name="txt" type="String">
        /// </param>
        /// <returns type="Object"></returns>
        if (!this._full$4) {
            txt = txt.replace(/([^,])\s*?\n/g, '$1,\n');
        }
        txt = txt.replace(/[,\s]+?\n/g, ',\n');
        txt = txt.replace(/[,\s]+$/g, '');
        if (this._full$4) {
            return JSON.parse(txt);
        }
        return JSON.parse('{' + txt + '}');
    },
    
    _customStuff$4: function EditProps$_customStuff$4() {
        Cluster.hiderElement.unbind('mousedown.swallowed').bind('mousedown.swallowed', ss.Delegate.create(this, function() {
            this.get_cancelBtn().click();
        }));
        $(document.body).bind('keydown.EditCssExamples', ss.Delegate.create(this, function(e) {
            if (e.which === 112) {
                this._examplesEv$4(e);
            }
        }));
        $('<span/>').appendTo(this.element).css({ position: 'absolute', top: 15, right: 15, cursor: 'pointer', color: 'blue' }).html('[help]').click(ss.Delegate.create(this, this._examplesEv$4));
    },
    
    _fullEv$4: function EditProps$_fullEv$4(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        this._full$4 = true;
        $('.Content', this.element).val(Rx.prettyJson(this._src$4 || {}));
    },
    
    _examplesEv$4: function EditProps$_examplesEv$4(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        DomElement.cancelEvent(e);
        var box = $("<div id='EditCssExamples' class='AboveHider Corners20'/>").insertAfter(this.element).css({ position: 'absolute', width: 500, height: 600, border: '5px solid green', background: '#FFC' }).bind('keydown', ss.Delegate.create(this, function(e3) {
            if (e3.which === 27) {
                this._closeHelpEv$4(e3);
            }
        }));
        box.position({ my: 'top center', at: 'top center', of: this.element });
        $('<span/>').appendTo(box).css({ position: 'absolute', top: 12, right: 10, cursor: 'pointer', color: 'blue' }).html('close').click(ss.Delegate.create(this, this._closeHelpEv$4));
        $("<textarea id='EditCssHelpTxt'/>").appendTo(box).css({ position: 'absolute', top: 34, right: 8, bottom: 10, left: 8, color: 'black', border: 'none', padding: '3px 5px' });
        Keys.filterAll(box);
        new Await().loadText('EditCssHelp', Uri.scripts('Data/EditCssHelp.txt')).handleDl(Exceptions.blobLoadError, Await.abortAw).addDx(function() {
            $('#EditCssHelpTxt').val(Await.files['EditCssHelp']).focus();
        }).commit();
    },
    
    _closeHelpEv$4: function EditProps$_closeHelpEv$4(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        if (e != null) {
            DomElement.cancelEvent(e);
        }
        $('#EditCssExamples').remove();
        $('.Content', this.element).focus();
    },
    
    _destroy$4: function EditProps$_destroy$4() {
        this._closeHelpEv$4(null);
        $(document.body).unbind('keydown.EditCssExamples');
    }
}


////////////////////////////////////////////////////////////////////////////////
// MinionsEdit.Classes.EvoEvents

MinionsEdit.Classes.EvoEvents = function MinionsEdit_Classes_EvoEvents() {
    /// <field name="redrawPageGear" type="String" static="true">
    /// </field>
    /// <field name="onPageSave" type="String" static="true">
    /// </field>
    /// <field name="setPageHeight" type="String" static="true">
    /// </field>
}


////////////////////////////////////////////////////////////////////////////////
// MiDrop

MiDrop = function MiDrop() {
    /// <field name="_dropOptions" type="Object" static="true">
    /// </field>
    /// <field name="_toId" type="String" static="true">
    /// </field>
    /// <field name="_ui" type="jQueryUiObject" static="true">
    /// </field>
}
MiDrop.makeDroppable = function MiDrop$makeDroppable(mm) {
    /// <param name="mm" type="MinionEdit">
    /// </param>
    mm.element.droppable(MiDrop._dropOptions);
}
MiDrop._dropOverEv = function MiDrop$_dropOverEv(e, ui) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    /// <param name="ui" type="jQueryUiObject">
    /// </param>
    var el = $(e.target).closest(Minion.dotMinionClassName);
    if (!el.length) {
        Inform.log('DropOver - err1 id={0}:{1}', e.target.tagName, e.target.id);
        debugger;
        return;
    }
    var mm = MinionEdit.getMinionFromEl(el);
    if (mm == null) {
        Inform.log('DropOver - err2 id={0}:{1}', e.target.tagName, e.target.id);
        debugger;
        return;
    }
    ui.e = e;
    MiMask.dropMaskOn(mm, ui);
}
MiDrop._dropOutEv = function MiDrop$_dropOutEv(e, ui) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    /// <param name="ui" type="jQueryUiObject">
    /// </param>
    var el = $(e.target).closest(Minion.dotMinionClassName);
    if (!el.length) {
        Inform.log('DropOut err1 id={0}:{1}', e.target.tagName, e.target.id);
        debugger;
        return;
    }
    var mm = MinionEdit.getMinionFromEl(el);
    if (mm == null) {
        Inform.log('DropOut err2 id={0}:{1}', e.target.tagName, e.target.id);
        debugger;
        return;
    }
    ui.draggable.removeClass('DropOver');
    ui.e = e;
    MiMask.dropMaskOff(mm, ui);
}
MiDrop._dropDropEv = function MiDrop$_dropDropEv(e, ui) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    /// <param name="ui" type="jQueryUiObject">
    /// </param>
    Inform.debug('DropDropEv()');
    if (MiUiOp.cancelled) {
        return;
    }
    var drop = MinionEdit.getMinionFromEv(e);
    var drag = MinionEdit.getMinionFromEl(ui.draggable);
    MiDrop._toId = drop.id;
    MiDrop._ui = ui;
    if (e.altKey) {
        new Await().addDx(function() {
            MiDrop._dropMove(e);
        }).commit();
        return;
    }
    var p = drop.element.offset();
    p.top += 7;
    p.left += 7;
    if (drag.get_parent() == null || drag.get_parent().id !== drop.id) {
        new MiPopChoice(e, p, { 'move as is': MiDrop._dropMove, 'move into this': MiDrop._dropInsert, 'copy into this': MiDrop._dropCopy, cancel: MiDrop._dropCancel }).css({ width: 160 }).setCancel(MiDrop._dropCancel);
        return;
    }
    MiMask.dropMaskOff(drop, MiDrop._ui);
}
MiDrop._dropInsert = function MiDrop$_dropInsert(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    var drag = MinionEdit.getMinionFromEl(MiDrop._ui.draggable);
    var drop = MinionEdit.getMinionById(MiDrop._toId);
    MiMask.dropMaskOff(drop, MiDrop._ui);
    if (drag != null) {
        new MinionPaste(drop).noOffset().paste(MiUiOp.get_snapshot());
        MiUiOp.get_theMinion().destroy();
    }
}
MiDrop._dropCopy = function MiDrop$_dropCopy(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    var drag = MinionEdit.getMinionFromEl(MiDrop._ui.draggable);
    var drop = MinionEdit.getMinionById(MiDrop._toId);
    MiMask.dropMaskOff(drop, MiDrop._ui);
    if (drag != null) {
        new MinionPaste(drop).noOffset().paste(MiUiOp.get_snapshot());
        MiUiOp.restore();
    }
}
MiDrop._dropMove = function MiDrop$_dropMove(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    var drop = MinionEdit.getMinionById(MiDrop._toId);
    MiMask.dropMaskOff(drop, MiDrop._ui);
}
MiDrop._dropCancel = function MiDrop$_dropCancel(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    var drop = MinionEdit.getMinionById(MiDrop._toId);
    MiMask.dropMaskOff(drop, MiDrop._ui);
    MiUiOp.restore();
}


////////////////////////////////////////////////////////////////////////////////
// MiPropPanel

MiPropPanel = function MiPropPanel() {
    /// <field name="_panelCss$4" type="String" static="true">
    /// </field>
    /// <field name="_currentTabIdx$4" type="Number" integer="true" static="true">
    /// </field>
    /// <field name="_instance$4" type="MiPropPanel" static="true">
    /// </field>
    /// <field name="_content$4" type="jQueryObject">
    /// </field>
    /// <field name="_tabPanels$4" type="Object">
    /// </field>
    /// <field name="_tabs$4" type="jQueryObject">
    /// </field>
    /// <field name="_tabsBox$4" type="jQueryObject">
    /// </field>
    /// <field name="queSave" type="Boolean">
    /// </field>
    /// <field name="_mm$4" type="MinionEdit">
    /// </field>
    /// <field name="_tabIdx$4" type="Number" integer="true">
    /// </field>
    this._tabPanels$4 = {};
    MiPropPanel.initializeBase(this);
    this.element.addClass('MiEditPanel');
    this._tabsBox$4 = $("<div class='MiEPLeft'/>").appendTo(this.element);
    this._content$4 = $("<div class='MiEPRight'/>").appendTo(this.element);
    this._tabs$4 = $("<ul class='MiEPTabs'/>").appendTo(this._tabsBox$4);
    this._refocus$4();
    this._tab$4('colors', 'object colors').click(ss.Delegate.create(this, this._colorsTabEv$4));
    this._tab$4('border', 'object background colors').click(ss.Delegate.create(this, this._borderTabEv$4));
    this._tab$4('font', 'font type and size').click(ss.Delegate.create(this, this._fontTabEv$4));
    this._tab$4('layer', 'layer properties').click(ss.Delegate.create(this, this._layerTabEv$4));
    if (!this._mm$4.get_data().relative) {
        this._tab$4('relative', 'make size relative to containing object').click(ss.Delegate.create(this, this.destroyEv)).click(MinionEdit.activeMakeRelativeEv);
    }
    this._tab$4('remove', 'remove the selected object').click(ss.Delegate.create(this, this.destroyEv)).click(MinionEdit.activeDeleteMinionEv);
}
MiPropPanel.ev = function MiPropPanel$ev(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    if (e.shiftKey) {
        return;
    }
    DomElement.cancelEvent(e);
    MinionEdit.maskSleeping = true;
    if (MiPropPanel._instance$4 == null) {
        MiPropPanel._instance$4 = new MiPropPanel();
    }
    MiPropPanel._instance$4.showEv(e);
}
MiPropPanel.prototype = {
    _content$4: null,
    _tabs$4: null,
    _tabsBox$4: null,
    queSave: false,
    _mm$4: null,
    _tabIdx$4: 0,
    
    get_units: function MiPropPanel$get_units() {
        /// <value type="String"></value>
        return MinionEdit.get_activeFocus().units;
    },
    
    _tab$4: function MiPropPanel$_tab$4(text, title) {
        /// <param name="text" type="String">
        /// </param>
        /// <param name="title" type="String">
        /// </param>
        /// <returns type="jQueryObject"></returns>
        var ti = this._tabIdx$4++;
        var tab = $('<li/>');
        tab.appendTo(this._tabs$4).html(text).attr('title', title).click(function() {
            $('.MiEPTabOn').removeClass('MiEPTabOn');
            tab.addClass('MiEPTabOn');
            MiPropPanel._currentTabIdx$4 = ti;
        });
        return tab;
    },
    
    showEv: function MiPropPanel$showEv(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        this._refocus$4();
        if (this._mm$4 != null) {
            var p = this._mm$4.element.offset();
            this.element.css({ top: p.top, left: p.left + this._mm$4.element.outerWidth() }).show().find('li').eq(MiPropPanel._currentTabIdx$4).trigger('click');
        }
        else {
            this.destroyEv(e);
        }
    },
    
    destroyEv: function MiPropPanel$destroyEv(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        MiPropPanel._instance$4 = null;
        MinionEdit.maskSleeping = false;
        MiPropPanel.callBaseMethod(this, 'destroyEv', [ e ]);
        if (this.queSave) {
            new Nsb.Classes.Evo().fireWith(ss.Delegate.create(MinionEdit.get_activeFocus(), MinionEdit.get_activeFocus().save));
        }
    },
    
    _refocus$4: function MiPropPanel$_refocus$4() {
        if (MinionEdit.get_activeFocus() != null) {
            this._mm$4 = MinionEdit.get_activeFocus();
        }
        else {
            this._mm$4 = null;
        }
    },
    
    _colorsTabEv$4: function MiPropPanel$_colorsTabEv$4(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        MiPropPage.ev(this, this._content$4).append(new MiColorWidget('Text', 'color')).newBox().append(new MiColorWidget('Background', 'background-color')).ender();
    },
    
    _borderTabEv$4: function MiPropPanel$_borderTabEv$4(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        MiPropPage.ev(this, this._content$4).append(new MiColorWidget('Border', 'border-color')).newBox().label('width').append(new MiBorderWidthWidget('BorderWidth', 'border-width', 0, 9)).label('').append(new MiBorderStyleWidget('style', 'border-style', { none: 'none', solid: 'solid', dotted: 'dotted', dashed: 'dashed', inset: 'inset', outset: 'outset', groove: 'groove', ridge: 'ridge', 'double': 'double' })).append(new MiBorderRadius('rounding', MiProperty.dictOf(0, 50))).label('padding').append(new MiPxWidget('top', 'padding-top', MiProperty.dictOf(0, 50))).append(new MiPxWidget('left', 'padding-left', MiProperty.dictOf(0, 50))).append(new MiPxWidget('right', 'padding-right', MiProperty.dictOf(0, 50))).append(new MiPxWidget('bottom', 'padding-bottom', MiProperty.dictOf(0, 50))).ender();
    },
    
    _fontTabEv$4: function MiPropPanel$_fontTabEv$4(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        MiPropPage.ev(this, this._content$4).append(new MiFontSizeWidget('FontSize', 'font-size', 7, 72)).ender();
    },
    
    _layerTabEv$4: function MiPropPanel$_layerTabEv$4(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        MiPropPage.ev(this, this._content$4).ender();
    }
}


////////////////////////////////////////////////////////////////////////////////
// MiKeyMap

MiKeyMap = function MiKeyMap() {
    /// <field name="_editKeys" type="Object" static="true">
    /// </field>
}
MiKeyMap.installEvents = function MiKeyMap$installEvents() {
    if (MiKeyMap._editKeys == null) {
        MiKeyMap._editKeys = { B: function(e) {
            MiKeyMap.onFocusDoEvo(e, ss.Delegate.create(MinionEdit.get_activeFocus(), MinionEdit.get_activeFocus().toBack));
        }, F: function(e) {
            MiKeyMap.onFocusDoEvo(e, ss.Delegate.create(MinionEdit.get_activeFocus(), MinionEdit.get_activeFocus().toFront));
        }, Ec: function(e) {
            MiKeyMap.onFocusDoEvo(e, MiMapActions.editMinionProps);
        }, '8:': MinionEdit.activeDeleteMinionEv, '8:s': MinionEdit.activeDeleteMinionEv, '46:': MinionEdit.activeDeleteMinionEv, '46:s': MinionEdit.activeDeleteMinionEv, Cc: MinionEdit.activeCopyEv, Vc: MinionEdit.activePasteEv, Rc: MinionEdit.activeRepaintEv, '27:': MiUiOp.abortEv };
    }
    $(document).bind('keydown.Minion', function(e) {
        Keys.doKeys(e, MiKeyMap._editKeys);
    });
    $(Minion.dotMinionClassName).live('mouseover.Minion', MinionEdit.mouseOverEv);
    $(Minion.dotMinionClassName).live('mouseleave.Minion', MinionEdit.mouseOutEv);
    $(Minion.dotMinionClassName).live('contextmenu.Minion', MiPropPanel.ev);
    $(document).bind('contextmenu', function(e) {
        Nsb.Classes.Evo.trigger('PageManagerEv', e);
    });
}
MiKeyMap.removeEvents = function MiKeyMap$removeEvents() {
    $(document).unbind('.Minion');
    $(Minion.dotMinionClassName).die('.Minion');
}
MiKeyMap.bailNoFocusEv = function MiKeyMap$bailNoFocusEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    /// <returns type="Boolean"></returns>
    if (!MiKeyMap.get_hasFocus()) {
        DomElement.cancelEvent(e);
        Cluster.flashWindow();
        return true;
    }
    return false;
}
MiKeyMap.get_hasFocus = function MiKeyMap$get_hasFocus() {
    /// <value type="Boolean"></value>
    return MinionEdit.get_activeFocus() != null;
}
MiKeyMap.onFocusDoEvo = function MiKeyMap$onFocusDoEvo(e, fn) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    /// <param name="fn" type="System.Action`1">
    /// </param>
    DomElement.cancelEvent(e);
    if (MinionEdit.get_activeFocus() != null) {
        Inform.debug('OnFocusDoEvo id={0}', MinionEdit.get_activeFocus().id);
        new Nsb.Classes.Evo().response(ss.Delegate.create(MinionEdit.get_activeFocus(), MinionEdit.get_activeFocus().save)).setValue(MinionEdit.get_activeFocus()).ev(e).fireWith(fn);
    }
    else {
        Cluster.flashWindow();
    }
}


////////////////////////////////////////////////////////////////////////////////
// MiMask

MiMask = function MiMask() {
    /// <field name="_mask1" type="jQueryObject" static="true">
    /// </field>
    /// <field name="_mask2" type="jQueryObject" static="true">
    /// </field>
    /// <field name="_sizer" type="jQueryObject" static="true">
    /// </field>
    /// <field name="_pos" type="Minions.Classes.Pos" static="true">
    /// </field>
    /// <field name="_wd" type="Number" static="true">
    /// </field>
    /// <field name="_ht" type="Number" static="true">
    /// </field>
    /// <field name="_once" type="Boolean" static="true">
    /// </field>
    /// <field name="_css" type="Object" static="true">
    /// </field>
    /// <field name="_sizercss" type="Object" static="true">
    /// </field>
}
MiMask._createMask = function MiMask$_createMask() {
    MiMask._once = false;
    $('.MinionSizer').remove();
    $('.MinionMask').remove();
    MiMask._mask1 = $("<div class='MinionMask'/>").css(MiMask._css);
    MiMask._mask2 = $("<div class='MinionMask'/>").css(MiMask._css).css({ 'border-color': '#f4f444', 'border-style': 'solid' });
    MiMask._sizer = $("<div class='MinionSizer'/>").css(MiMask._sizercss).appendTo(MiMask._mask1);
}
MiMask._getMetrics = function MiMask$_getMetrics(el) {
    /// <param name="el" type="jQueryObject">
    /// </param>
    var offsetTop = parseInt(el.css('border-top-width')) + 3;
    var offsetLeft = parseInt(el.css('border-left-width')) + 3;
    MiMask._pos = new Minions.Classes.Pos();
    MiMask._wd = el.outerWidth();
    MiMask._ht = el.outerHeight();
    MiMask._pos.top -= offsetTop;
    MiMask._pos.left -= offsetLeft;
}
MiMask._reMask = function MiMask$_reMask(mm) {
    /// <param name="mm" type="Minion">
    /// </param>
    if (mm != null) {
        if (!MiMask._once) {
            MiMask._sizer.append($("<img src='" + Uri.img('Common/dragger.png') + "' style='position:absolute;top:0;left:0;width:100%;height:100%'/>")).mousedown(MiMask._sizerEv);
            MiMask._once = true;
        }
        MiMask._getMetrics(mm.element);
        var bdrrad = { 'border-radius': mm.element.css('border-top-left-radius') };
        MiMask._mask1.prependTo(mm.element).css({ top: MiMask._pos.top, left: MiMask._pos.left, width: MiMask._wd, height: MiMask._ht }).copyRadius(bdrrad, 2, 'px').show();
        MiMask._mask2.prependTo(mm.element).css({ top: MiMask._pos.top, left: MiMask._pos.left, width: MiMask._wd, height: MiMask._ht }).copyRadius(bdrrad, 2, 'px').show();
        MiMask._sizer.css({ top: MiMask._ht - 6, left: MiMask._wd - 6 });
        if (!MiMask._mask1.is(':visible')) {
            Inform.error('ReMask not visible id={0}', mm.get_data().id);
            MiMask._createMask();
            MiMask._reMask(mm);
        }
    }
}
MiMask._sizerEv = function MiMask$_sizerEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    if (MinionEdit.get_activeFocus() != null) {
        new Nsb.Classes.Evo().evoke(ss.Delegate.create(MinionEdit.get_activeFocus(), MinionEdit.get_activeFocus().resize)).ev(e).fire();
    }
}
MiMask.maskOn = function MiMask$maskOn(mm) {
    /// <param name="mm" type="MinionEdit">
    /// </param>
    if (MinionEdit.maskSleeping) {
        return;
    }
    if (mm != null) {
        if (MiMask._mask1.parent()[0] !== mm.element[0]) {
            MiMask._reMask(mm);
        }
        else {
            MiMask._mask1.show();
            MiMask._mask2.show();
            if (!MiMask._mask1.is(':visible')) {
                Inform.error('MaskOn not visible id={0}', mm.get_data().id);
                MiMask._createMask();
                MiMask._reMask(mm);
            }
        }
    }
    else {
        Inform.debug('MaskOn2');
    }
}
MiMask.maskOff = function MiMask$maskOff() {
    MiMask._mask1.appendTo(document.body).hide();
    MiMask._mask2.appendTo(document.body).hide();
    MinionEdit.maskSleeping = false;
}
MiMask.maskSleep = function MiMask$maskSleep() {
    MiMask.maskOff();
    MinionEdit.maskSleeping = true;
}
MiMask.maskWake = function MiMask$maskWake(mm) {
    /// <param name="mm" type="MinionEdit">
    /// </param>
    ss.Debug.assert(mm != null, 'Requires MinionEdit arg');
    MinionEdit.maskSleeping = false;
    MiMask.maskOn(mm);
    MiMask._reMask(mm);
}
MiMask.maskRubberband = function MiMask$maskRubberband(mm) {
    /// <param name="mm" type="MinionEdit">
    /// </param>
    ss.Debug.assert(mm != null, 'Requires MinionEdit arg');
    MiMask._reMask(mm);
}
MiMask.dropMaskOn = function MiMask$dropMaskOn(mm, ui) {
    /// <param name="mm" type="MinionEdit">
    /// </param>
    /// <param name="ui" type="jQueryUiObject">
    /// </param>
    ss.Debug.assert(mm != null, 'Requires MinionEdit arg');
    Inform.log('DropOver id={0}:{1}', mm.element[0].tagName, mm.id);
    $("<div class='DropMask'/>").html(ThemeBase.hearts).css({ position: 'absolute', top: 0, left: 0, color: 'red' }).appendTo(mm.element);
    mm.addClass('DropOver');
}
MiMask.dropMaskOff = function MiMask$dropMaskOff(mm, ui) {
    /// <param name="mm" type="MinionEdit">
    /// </param>
    /// <param name="ui" type="jQueryUiObject">
    /// </param>
    ss.Debug.assert(mm != null && ui != null, 'Requires MinionEdit and ui arg');
    Inform.log('DropOut id={0}:{1}', mm.element[0].tagName, mm.id);
    $('.DropMask').remove();
    $('.DropOver').removeClass('DropOver');
}


////////////////////////////////////////////////////////////////////////////////
// MiCanvasEdit

MiCanvasEdit = function MiCanvasEdit() {
    /// <field name="lastSaved" type="String">
    /// </field>
    MiCanvasEdit.initializeBase(this);
}
MiCanvasEdit.flashWindowEv = function MiCanvasEdit$flashWindowEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    Cluster.flashWindow();
}
MiCanvasEdit.prototype = {
    lastSaved: null,
    
    saveAw: function MiCanvasEdit$saveAw(evo) {
        /// <param name="evo" type="Nsb.Classes.Evo">
        /// </param>
        var awp = evo.takeAndOwnResponse();
        ss.Debug.assert(awp != null, 'SaveAw awp != null');
        ss.Debug.assert(this.get_partitionKey() != null && this.get_rowKey() != null, 'MiCanvasEdit.SaveAw PartionKey & RowKey not null');
        var noUndo = evo.value;
        new Await().addDx(ss.Delegate.create(this, function() {
            var content = '[' + JSON.stringify(this.get_liveCanvasData(), function(n, o) {
                return o;
            }, 4) + ']';
            if (content !== this.lastSaved) {
                if (!noUndo) {
                    Undo.save(new MinionsEdit.Classes.UndoItem(content), this.get_partitionKey());
                    Nsb.Classes.Evo.trigger('RedrawPageGear');
                }
                this.lastSaved = content;
                Nsb.Classes.Evo.triggerAw(awp, Nsb.Classes.Evo.storeBlobAw, { partitionKey: this.get_partitionKey(), rowKey: this.get_rowKey(), content: content, backup: true });
                Nsb.Classes.Evo.trigger('OnPageSave');
            }
            else {
                awp.done();
            }
        })).addDx(function() {
            Nsb.Classes.Evo.trigger('SetPageHeight');
        }).commit();
    },
    
    get_liveCanvasData: function MiCanvasEdit$get_liveCanvasData() {
        /// <value type="Minions.Classes.MiCanvasData"></value>
        this.get_theCanvas().get_canvasData().minion = this.get_liveData();
        return this.get_theCanvas().get_canvasData();
    },
    
    newMinion: function MiCanvasEdit$newMinion(top) {
        /// <param name="top" type="Minion">
        /// </param>
        /// <returns type="Minion"></returns>
        return new MiCanvasEdit().setTop(top);
    }
}


////////////////////////////////////////////////////////////////////////////////
// MiMetrics

MiMetrics = function MiMetrics() {
    /// <field name="minWidth" type="Number" static="true">
    /// </field>
    /// <field name="minHeight" type="Number" static="true">
    /// </field>
    /// <field name="dx" type="Number">
    /// </field>
    /// <field name="dy" type="Number">
    /// </field>
    /// <field name="handle" type="jQueryObject">
    /// </field>
    /// <field name="iPos" type="Array" elementType="Number">
    /// </field>
    /// <field name="stDim" type="Minions.Classes.Dimension">
    /// </field>
    /// <field name="stOff" type="Minions.Classes.Pos">
    /// </field>
    /// <field name="_bdrX" type="Number">
    /// </field>
    /// <field name="_bdrY" type="Number">
    /// </field>
    /// <field name="_ratioX" type="Number">
    /// </field>
    /// <field name="_ratioY" type="Number">
    /// </field>
    /// <field name="_element" type="jQueryObject">
    /// </field>
    /// <field name="_enPos" type="Minions.Classes.Pos">
    /// </field>
    /// <field name="_fromId" type="String">
    /// </field>
    /// <field name="_mm" type="MinionEdit">
    /// </field>
    /// <field name="_parentHt" type="Number">
    /// </field>
    /// <field name="_parentWd" type="Number">
    /// </field>
    /// <field name="_working" type="Boolean">
    /// </field>
    this.stDim = new Minions.Classes.Dimension();
}
MiMetrics.prototype = {
    dx: 0,
    dy: 0,
    handle: null,
    iPos: null,
    stOff: null,
    _bdrX: 0,
    _bdrY: 0,
    _ratioX: 0,
    _ratioY: 0,
    _element: null,
    _enPos: null,
    _fromId: null,
    _mm: null,
    _parentHt: 0,
    _parentWd: 0,
    _working: false,
    
    get_enPos: function MiMetrics$get_enPos() {
        /// <value type="Minions.Classes.Pos"></value>
        return Minions.Classes.Pos.clone(this._enPos);
    },
    
    get__theMinion: function MiMetrics$get__theMinion() {
        /// <value type="MinionEdit"></value>
        return MinionEdit.getMinionById(this._fromId);
    },
    
    _initialize: function MiMetrics$_initialize(e, ui) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        /// <param name="ui" type="jQueryUiObject">
        /// </param>
        if (this._working) {
            throw new Error('Double use of MiMetrics');
        }
        this._working = true;
        this._element = $(e.target).closest(Minion.dotMinionClassName);
        this._mm = MinionEdit.getMinionFromEl(this._element);
        MiUiOp.init(this._mm, e, ui);
        this._fromId = this._mm.id;
        var parent = this._element.offsetParent();
        ss.Debug.assert(parent != null, 'offset parent != null');
        this._parentWd = parent.width();
        this._parentHt = parent.height();
    },
    
    _finish: function MiMetrics$_finish() {
        this._working = false;
    },
    
    _reElement: function MiMetrics$_reElement() {
        this._mm = this.get__theMinion();
        this._element = this._mm.element;
    },
    
    _cwd: function MiMetrics$_cwd(n) {
        /// <param name="n" type="Number">
        /// </param>
        /// <returns type="Number"></returns>
        return ((this._mm.get_data().relative) ? (n / this._parentWd * 100) : n);
    },
    
    _ch: function MiMetrics$_ch(n) {
        /// <param name="n" type="Number">
        /// </param>
        /// <returns type="String"></returns>
        return ((this._mm.get_data().relative) ? (n / this._parentHt * 100) : n) + this._mm.units;
    },
    
    snapDragStart: function MiMetrics$snapDragStart(e, ui) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        /// <param name="ui" type="jQueryUiObject">
        /// </param>
        /// <returns type="MiMetrics"></returns>
        this._initialize(e, ui);
        this._element.droppable({ disabled: true });
        MiUiOp.setCancel(ss.Delegate.create(this, function() {
            this.get__theMinion().element.trigger('mouseup');
        }));
        this.stOff = this._element.offset();
        this.stDim.width = this._element.outerWidth();
        this.stDim.height = this._element.outerHeight();
        var tilt = Math.abs(this._element[0].tilt);
        if (tilt > 0) {
            var ww = this.stDim.width;
            var hh = this.stDim.height;
            var tt = this._element.snapToTilt(tilt);
            this.stDim.width = this._element.snapToTiltW(tt, ww, hh);
            this.stDim.height = this._element.snapToTiltH(tt, ww, hh);
        }
        this._element.addClass('GigMe');
        this._element.find(Minion.dotMinionClassName).addClass('GigMe');
        this._element.snapCollect('div.Gig:not(' + MinionEdit.dotGigMe + ')');
        return this;
    },
    
    snapDragDrag: function MiMetrics$snapDragDrag(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        var p = this._element.offset();
        if (e.altKey) {
            this.iPos = [ p.left, p.top ];
        }
        else {
            this.iPos = this._element.snapPos(p.left, p.top, this.stDim.width, this.stDim.height);
        }
    },
    
    snapDragStop: function MiMetrics$snapDragStop(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        this._reElement();
        this._element.show();
        if (MiUiOp.cancelled) {
            this._element.snapDump();
            this._element.droppable({ disabled: false });
            MiUiOp.finish();
            this._finish();
            return;
        }
        var p = this._element.offset();
        if (!e.altKey) {
            this.iPos = this._element.snapPos(p.left, p.top, this.stDim.width, this.stDim.height);
            this._element.offset({ top: this.iPos[1], left: this.iPos[0] });
        }
        else {
            this.iPos = [ p.left, p.top ];
        }
        this._element.snapDump();
        this.dx = this.iPos[0] - this.stOff.left;
        this.dy = this.iPos[1] - this.stOff.top;
        this._enPos = this._cvPos(this._element.position());
        this._mm.get_data().pos = this.get_enPos();
        this._mm.paintMetrics(true);
        $(MinionEdit.dotGigMe).removeClass('GigMe');
        this._element.droppable({ disabled: false });
        MiUiOp.finish();
        this._finish();
    },
    
    _cvPos: function MiMetrics$_cvPos(p) {
        /// <param name="p" type="Minions.Classes.Pos">
        /// </param>
        /// <returns type="Minions.Classes.Pos"></returns>
        if (this._mm.get_data().relative) {
            var fh = this._mm.get_data().offsetParentWidth / this._element.offsetParent().width();
            var fv = this._mm.get_data().offsetParentHeight / this._element.offsetParent().height();
            p.top *= fv;
            p.left *= fh;
        }
        return p;
    },
    
    snapResizeStart: function MiMetrics$snapResizeStart(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        /// <returns type="MiMetrics"></returns>
        this._initialize(e);
        this._element.draggable('disable');
        MiUiOp.setCancel(function() {
            $(document).trigger('mouseup');
        });
        Nsb.Classes.Evo.trigger('MaskSleepEv');
        Nsb.Classes.Evo.trigger('MaskRubberbandEv', this._mm);
        $(document).bind('mousemove.MinionSize', ss.Delegate.create(this, this._snapResizeMove));
        $(document).bind('mouseup.MinionSize', ss.Delegate.create(this, this._snapResizeStop));
        DomElement.cancelEvent(e);
        if (this._element.length > 0) {
            this.stDim.width = this._element.outerWidth();
            this.stDim.height = this._element.outerHeight();
            this._ratioX = this._mm.get_data().dim.width / this._element.width();
            this._ratioY = this._mm.get_data().dim.height / this._element.height();
            this._bdrX = this.stDim.width - this._element.width();
            this._bdrY = this.stDim.height - this._element.height();
            var tilt = Math.abs(this._element[0].tilt);
            if (tilt > 0) {
                var ww = this.stDim.width;
                var hh = this.stDim.height;
                var tt = this._element.snapToTilt(tilt);
                this.stDim.width = this._element.snapToTiltW(tt, ww, hh);
                this.stDim.height = this._element.snapToTiltH(tt, ww, hh);
            }
            this._element.addClass('GigMe');
            this._element.snapCollect('div.Gig:not(' + MinionEdit.dotGigMe + ')');
            this._element.removeClass('GigMe');
            this.iPos = [ this.stDim.width, this.stDim.height ];
        }
        return this;
    },
    
    _snapResizeMove: function MiMetrics$_snapResizeMove(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        DomElement.cancelEvent(e);
        if (this._element.length > 0) {
            var p = this._element.offset();
            var wd = Math.max(e.pageX - p.left - this._bdrX, MiMetrics.minWidth);
            var ht = Math.max(e.pageY - p.top - this._bdrY, MiMetrics.minHeight);
            var ow = wd + this._bdrX;
            var oh = ht + this._bdrY;
            this.iPos = this._element.snapDim(this._element.offset().left + ow, this._element.offset().top + oh, Math.round(ow / 2), Math.round(oh / 2));
            var md = this._mm.get_data();
            if (md.relative) {
                wd *= this._ratioX;
                ht *= this._ratioY;
            }
            md.dim.width = wd;
            md.dim.height = ht;
            this._mm.paintMetrics();
            Nsb.Classes.Evo.trigger('MaskRubberbandEv', this._mm);
        }
    },
    
    _snapResizeStop: function MiMetrics$_snapResizeStop(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        this._reElement();
        $(document).unbind('.MinionSize');
        this._element.draggable('enable');
        if (!MiUiOp.cancelled) {
            Nsb.Classes.Evo.trigger('MaskOffEv', this._mm);
            if (('TestRepaintAll' in window.self)) {
                var id = this._mm.id;
                new Nsb.Classes.Evo().fireWith(ss.Delegate.create(this._mm, this._mm.rePaintCanvas));
                this._mm = Minion.getMinionById(id);
            }
            new Nsb.Classes.Evo().fireWith(ss.Delegate.create(this._mm, this._mm.save));
        }
        MiUiOp.finish();
        this._finish();
    },
    
    _cvDim: function MiMetrics$_cvDim(m) {
        /// <param name="m" type="Minions.Classes.Dimension">
        /// </param>
        /// <returns type="Minions.Classes.Dimension"></returns>
        if (this._mm.get_data().relative) {
            var fh = this._mm.get_data().offsetParentWidth / this._element.offsetParent().width();
            var fv = this._mm.get_data().offsetParentHeight / this._element.offsetParent().height();
            m.width = Math.round(m.width * fh);
            m.height = Math.round(m.height * fv);
        }
        return m;
    }
}


////////////////////////////////////////////////////////////////////////////////
// MinionEdit

MinionEdit = function MinionEdit() {
    /// <field name="gigMe" type="String" static="true">
    /// </field>
    /// <field name="dotGigMe" type="String" static="true">
    /// </field>
    /// <field name="minSize" type="Number" static="true">
    /// </field>
    /// <field name="maskOnEv" type="String" static="true">
    /// </field>
    /// <field name="maskOffEv" type="String" static="true">
    /// </field>
    /// <field name="maskSleepEv" type="String" static="true">
    /// </field>
    /// <field name="maskWakeEv" type="String" static="true">
    /// </field>
    /// <field name="maskRubberbandEv" type="String" static="true">
    /// </field>
    /// <field name="uploadImgEv" type="String" static="true">
    /// </field>
    /// <field name="pageManagerEv" type="String" static="true">
    /// </field>
    /// <field name="_activeFocus$4" type="MinionEdit" static="true">
    /// </field>
    /// <field name="editKeys" type="Object" static="true">
    /// </field>
    /// <field name="maskSleeping" type="Boolean" static="true">
    /// </field>
    /// <field name="_dragOptions$4" type="Object">
    /// </field>
    /// <field name="_snapToNone$4" type="jQueryObject">
    /// </field>
    /// <field name="_dropTarget$4" type="Boolean">
    /// </field>
    /// <field name="_mx$4" type="MiMetrics">
    /// </field>
    this._snapToNone$4 = jQuery();
    MinionEdit.initializeBase(this);
    this.set_editing(true);
    this._dragOptions$4 = { start: ss.Delegate.create(this, this._dragStart$4), drag: ss.Delegate.create(this, this._dragDrag$4), stop: ss.Delegate.create(this, this._dragStop$4) };
}
MinionEdit.getMinionById = function MinionEdit$getMinionById(id) {
    /// <param name="id" type="String">
    /// </param>
    /// <returns type="MinionEdit"></returns>
    return Minion.getMinionById(id);
}
MinionEdit.getMinionFromEl = function MinionEdit$getMinionFromEl(el) {
    /// <param name="el" type="jQueryObject">
    /// </param>
    /// <returns type="MinionEdit"></returns>
    return MinionEdit.getMinionById(el.attr('id'));
}
MinionEdit.getMinionFromEv = function MinionEdit$getMinionFromEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    /// <returns type="MinionEdit"></returns>
    try {
        return MinionEdit.getMinionFromEl($(e.target).closest(Minion.dotMinionClassName));
    }
    catch ($e1) {
        debugger;
        return null;
    }
}
MinionEdit.get_activeFocus = function MinionEdit$get_activeFocus() {
    /// <value type="MinionEdit"></value>
    return MinionEdit._activeFocus$4;
}
MinionEdit.set_activeFocus = function MinionEdit$set_activeFocus(value) {
    /// <value type="MinionEdit"></value>
    MinionEdit._activeFocus$4 = value;
    return value;
}
MinionEdit.get_activeParent = function MinionEdit$get_activeParent() {
    /// <value type="MinionEdit"></value>
    return (MinionEdit._activeFocus$4 != null) ? MinionEdit._activeFocus$4.get_parent() : null;
}
MinionEdit.get_activeChildren = function MinionEdit$get_activeChildren() {
    /// <value type="Object"></value>
    return (MinionEdit._activeFocus$4 != null) ? MinionEdit._activeFocus$4.get_parent().children : null;
}
MinionEdit.get_activeData = function MinionEdit$get_activeData() {
    /// <value type="Minions.Classes.MinionData"></value>
    return (MinionEdit._activeFocus$4 != null) ? MinionEdit._activeFocus$4.get_liveData() : null;
}
MinionEdit.get_activeCanvas = function MinionEdit$get_activeCanvas() {
    /// <value type="MiCanvas"></value>
    return (MinionEdit._activeFocus$4 != null) ? MinionEdit._activeFocus$4.get_theCanvas() : null;
}
MinionEdit.get_activeCanvasData = function MinionEdit$get_activeCanvasData() {
    /// <value type="Minions.Classes.MiCanvasData"></value>
    return (MinionEdit.get_activeCanvas() != null) ? MinionEdit.get_activeCanvas().get_canvasData() : null;
}
MinionEdit.get_focusOrFlash = function MinionEdit$get_focusOrFlash() {
    /// <value type="Boolean"></value>
    if (MinionEdit.get_activeFocus() == null) {
        Cluster.flashWindow();
        return false;
    }
    return true;
}
MinionEdit.get_canvasOrFlash = function MinionEdit$get_canvasOrFlash() {
    /// <value type="Boolean"></value>
    if (MinionEdit.get_activeFocus() == null || MinionEdit.get_activeFocus().get_topMinionEdit() == null) {
        Cluster.flashWindow();
        return false;
    }
    return true;
}
MinionEdit.pagesEv = function MinionEdit$pagesEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    if (!e.shiftKey) {
        Cluster.glassOff();
        MinionsEdit.Classes.Pages.Ev(e);
    }
}
MinionEdit.mouseOverEv = function MinionEdit$mouseOverEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    DomElement.cancelEvent(e);
    if (!MinionEdit.maskSleeping) {
        var mm = MinionEdit.getMinionFromEv(e);
        if (mm.element.width() >= 20) {
            MinionEdit.set_activeFocus(mm);
            Nsb.Classes.Evo.trigger('MaskOnEv', MinionEdit.get_activeFocus());
        }
    }
}
MinionEdit.mouseOutEv = function MinionEdit$mouseOutEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    DomElement.cancelEvent(e);
    if (!MinionEdit.maskSleeping) {
        Nsb.Classes.Evo.trigger('MaskOffEv');
        MinionEdit.set_activeFocus(null);
    }
}
MinionEdit.activeDeleteMinionEv = function MinionEdit$activeDeleteMinionEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    DomElement.cancelEvent(e);
    if (MinionEdit.get_focusOrFlash()) {
        MinionEdit.get_activeFocus().deleteMinion(e.shiftKey);
    }
}
MinionEdit.activeCopyEv = function MinionEdit$activeCopyEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    DomElement.cancelEvent(e);
    if (MinionEdit.get_focusOrFlash()) {
        MinionEdit.get_activeFocus().copyMinion(e.shiftKey);
    }
}
MinionEdit.activeMakeRelativeEv = function MinionEdit$activeMakeRelativeEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    DomElement.cancelEvent(e);
    if (MinionEdit.get_focusOrFlash() && MinionEdit.get_activeFocus().get_parent() != null) {
        MinionEdit.get_activeFocus().convertToRelativeMetrics(MinionEdit.get_activeFocus().get_parent());
    }
}
MinionEdit.activePasteEv = function MinionEdit$activePasteEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    DomElement.cancelEvent(e);
    if (MinionEdit.get_focusOrFlash()) {
        new MinionPaste(MinionEdit.get_activeFocus()).pasteEv(e);
    }
}
MinionEdit.activeRepaintEv = function MinionEdit$activeRepaintEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    DomElement.cancelEvent(e);
    var $dict1 = Minion.get_all();
    for (var $key2 in $dict1) {
        var pair = { key: $key2, value: $dict1[$key2] };
        if (pair.value.get_parent() == null) {
            new Nsb.Classes.Evo().fireWith(ss.Delegate.create(pair.value, pair.value.rePaintCanvas));
        }
    }
    Cluster.flashWindow('green');
}
MinionEdit.prototype = {
    _dragOptions$4: null,
    _dropTarget$4: false,
    _mx$4: null,
    
    get_topMinionEdit: function MinionEdit$get_topMinionEdit() {
        /// <value type="MinionEdit"></value>
        return this.get_topMinion();
    },
    
    get_dropTarget: function MinionEdit$get_dropTarget() {
        /// <value type="Boolean"></value>
        return this._dropTarget$4;
    },
    set_dropTarget: function MinionEdit$set_dropTarget(value) {
        /// <value type="Boolean"></value>
        this._dropTarget$4 = value;
        return value;
    },
    
    get__parentElement$4: function MinionEdit$get__parentElement$4() {
        /// <value type="jQueryObject"></value>
        return (this.get_parent() != null) ? this.get_parent().element : null;
    },
    
    get_hasFocus: function MinionEdit$get_hasFocus() {
        /// <value type="Boolean"></value>
        return MinionEdit.get_activeFocus() === this;
    },
    
    get_snapShot: function MinionEdit$get_snapShot() {
        /// <value type="String"></value>
        var md = this.get_liveData();
        return JSON.stringify(md);
    },
    
    newMinion: function MinionEdit$newMinion(top) {
        /// <param name="top" type="Minion">
        /// </param>
        /// <returns type="Minion"></returns>
        return new MinionEdit().setTop(top);
    },
    
    insert: function MinionEdit$insert(before, after) {
        /// <param name="before" type="Minion">
        /// </param>
        /// <param name="after" type="Minion">
        /// </param>
        before.element.insertBefore(after.element);
        new Nsb.Classes.Evo().fireWith(ss.Delegate.create(this, this.resort));
    },
    
    copyMinion: function MinionEdit$copyMinion(group) {
        /// <param name="group" type="Boolean">
        /// </param>
        MinionPaste.copy(this);
    },
    
    deleteMinion: function MinionEdit$deleteMinion(immediate) {
        /// <param name="immediate" type="Boolean">
        /// </param>
        Nsb.Classes.Evo.trigger('MaskOffEv');
        MinionEdit.callBaseMethod(this, 'deleteMinion', [ immediate ]);
    },
    
    draggable: function MinionEdit$draggable() {
        this.element.draggable(this._dragOptions$4);
    },
    
    droppable: function MinionEdit$droppable() {
        MiDrop.makeDroppable(this);
    },
    
    _remFromParent$4: function MinionEdit$_remFromParent$4() {
        if (this.get_parent() != null) {
            delete this.get_parent().children[this.id];
        }
        this.set_parent(null);
    },
    
    _dragStart$4: function MinionEdit$_dragStart$4(e, ui) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        /// <param name="ui" type="jQueryUiObject">
        /// </param>
        Inform.debug('MinionEdit.DragStart({0})', this.id);
        Nsb.Classes.Evo.trigger('MaskSleepEv');
        Nsb.Classes.Evo.trigger('MaskRubberbandEv', this);
        this._mx$4 = new MiMetrics().snapDragStart(e, ui);
    },
    
    _dragDrag$4: function MinionEdit$_dragDrag$4(e, ui) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        /// <param name="ui" type="jQueryUiObject">
        /// </param>
        this._mx$4.snapDragDrag(e);
    },
    
    _dragStop$4: function MinionEdit$_dragStop$4(e, ui) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        /// <param name="ui" type="jQueryUiObject">
        /// </param>
        Inform.debug('MinionEdit.DragStop()');
        this._mx$4.snapDragStop(e);
        Nsb.Classes.Evo.trigger('MaskWakeEv', this);
        if (('TestRepaintAll' in window.self)) {
            window.setTimeout(ss.Delegate.create(this, function() {
                new Nsb.Classes.Evo().fireWith(ss.Delegate.create(this, this.rePaintCanvas));
                Nsb.Classes.Evo.trigger('MaskOnEv', this);
            }), 1);
        }
        new Nsb.Classes.Evo().fireWith(ss.Delegate.create(this, this.save));
    },
    
    rePaintAndSave: function MinionEdit$rePaintAndSave(evo) {
        /// <param name="evo" type="Nsb.Classes.Evo">
        /// </param>
        this.rePaint(evo);
        new Nsb.Classes.Evo().fireWith(ss.Delegate.create(this, this.save));
    },
    
    resizeFixedChildMetrics: function MinionEdit$resizeFixedChildMetrics(ratio) {
        /// <param name="ratio" type="Number">
        /// </param>
        var $dict1 = this.children;
        for (var $key2 in $dict1) {
            var pair = { key: $key2, value: $dict1[$key2] };
            var md = pair.value.get_data();
            if (!md.relative) {
                md.dim.width *= ratio;
                md.dim.height *= ratio;
                md.pos.left *= ratio;
                md.pos.top *= ratio;
                pair.value.paintMetrics();
            }
            pair.value.resizeFixedChildMetrics(ratio);
        }
    },
    
    erase: function MinionEdit$erase() {
        /// <summary>
        /// Erases from dom and parent. The reverse of Paint()
        /// </summary>
        /// <returns type="MinionEdit"></returns>
        this.element.empty().remove();
        this._remFromParent$4();
        return this;
    },
    
    restoreFrom: function MinionEdit$restoreFrom(snapshot) {
        /// <param name="snapshot" type="String">
        /// </param>
        /// <returns type="MinionEdit"></returns>
        Nsb.Classes.Evo.trigger('MaskOffEv', this);
        var placeholder = $('<div/>').insertAfter(this.element);
        this.element.empty();
        this.setData(JSON.parse(snapshot)).paint();
        this.element.insertBefore(placeholder);
        placeholder.remove();
        return this;
    },
    
    installPageGear: function MinionEdit$installPageGear() {
        /// <returns type="MinionEdit"></returns>
        MiPageGear.installPageGear();
        return this;
    },
    
    convertToRelativeMetrics: function MinionEdit$convertToRelativeMetrics(parent) {
        /// <param name="parent" type="Minion">
        /// </param>
        /// <returns type="MinionEdit"></returns>
        if (!this.get_data().relative && parent != null) {
            this.get_data().relative = true;
            this.get_data().offsetParentWidth = this.element.offsetParent().width();
            this.get_data().offsetParentHeight = this.element.offsetParent().height();
            this.units = '%';
            this.paintMetrics();
            var $dict1 = this.children;
            for (var $key2 in $dict1) {
                var pair = { key: $key2, value: $dict1[$key2] };
                pair.value.convertToRelativeMetrics(this);
            }
        }
        return this;
    },
    
    resizeFixedMetrics: function MinionEdit$resizeFixedMetrics(newParent) {
        /// <param name="newParent" type="Minion">
        /// </param>
        /// <returns type="MinionEdit"></returns>
        if (newParent == null) {
            return this;
        }
        if (!this.get_data().relative) {
            var nw = newParent.element.width();
            var nh = newParent.element.height();
            if (this.get_data().dim.width + 20 > nw || this.get_data().dim.height + 20 > nh) {
                var ratio;
                if (this.get_data().dim.width > this.get_data().dim.height) {
                    ratio = nw / 2 / this.get_data().dim.width;
                    this.get_data().dim.width = nw / 2;
                    this.get_data().dim.height = this.get_data().dim.height * ratio;
                    this.get_data().pos.top = (nh - this.get_data().dim.height) / 2;
                    this.get_data().pos.left = nw / 4;
                }
                else {
                    ratio = nh / 2 / this.get_data().dim.height;
                    this.get_data().dim.height = nh / 2;
                    this.get_data().dim.width = this.get_data().dim.width * ratio;
                    this.get_data().pos.top = nh / 4;
                    this.get_data().pos.left = (nw - this.get_data().dim.width) / 2;
                }
                this.resizeFixedChildMetrics(ratio);
            }
            else {
                this.get_data().pos.left = (nw - this.get_data().dim.width) / 2;
                this.get_data().pos.top = (nh - this.get_data().dim.height) / 2;
            }
            this.paintMetrics();
        }
        else {
            var ratio = (this.get_data().offsetParentWidth > 0) ? (newParent.element.width() / this.get_data().offsetParentWidth) : 1;
            this.resizeFixedChildMetrics(ratio);
        }
        return this;
    },
    
    undoEv: function MinionEdit$undoEv(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        DomElement.cancelEvent(e);
        var ui = Undo.prior(this.get_partitionKey());
        if (ui != null) {
            new Nsb.Classes.Evo().fireWith(ss.Delegate.create(this, this.rePaintCanvas));
        }
    },
    
    redoEv: function MinionEdit$redoEv(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        DomElement.cancelEvent(e);
        var ui = Undo.next(this.get_partitionKey());
        if (ui != null) {
            new Nsb.Classes.Evo().fireWith(ss.Delegate.create(this, this.rePaintCanvas));
        }
    },
    
    refreshPageGear: function MinionEdit$refreshPageGear(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
    },
    
    rePaint: function MinionEdit$rePaint(evo) {
        /// <param name="evo" type="Nsb.Classes.Evo">
        /// </param>
        if (MinionEdit.get_activeFocus() != null && MinionEdit.get_activeFocus().id === this.id) {
            MinionEdit.set_activeFocus(null);
        }
        Nsb.Classes.Evo.trigger('MaskOffEv');
        MinionEdit.callBaseMethod(this, 'rePaint', [ evo ]);
    },
    
    resize: function MinionEdit$resize(evo) {
        /// <param name="evo" type="Nsb.Classes.Evo">
        /// </param>
        Inform.debug('MinionEdit.Resize({0})', this.id);
        this._mx$4 = new MiMetrics().snapResizeStart(evo.event);
    },
    
    save: function MinionEdit$save(evo) {
        /// <param name="evo" type="Nsb.Classes.Evo">
        /// </param>
        this.unsaved = true;
        if (this.get_partitionKey() == null) {
            new Nsb.Classes.Evo().response(ss.Delegate.create(this, function() {
                this.unsaved = false;
            })).evoke(ss.Delegate.create(this.get_topMinionEdit(), this.get_topMinionEdit().saveAw)).setValue(Undo.allowUndo).fire(Await.get_asyncAw());
        }
        else {
            new Nsb.Classes.Evo().response(ss.Delegate.create(this, function() {
                this.unsaved = false;
            })).evoke(ss.Delegate.create(this, this.saveMeAw)).setValue(Undo.allowUndo).fire(Await.get_asyncAw());
        }
    },
    
    saveAw: function MinionEdit$saveAw(evo) {
        /// <param name="evo" type="Nsb.Classes.Evo">
        /// </param>
    },
    
    saveMeAw: function MinionEdit$saveMeAw(evo) {
        /// <param name="evo" type="Nsb.Classes.Evo">
        /// </param>
    },
    
    toFront: function MinionEdit$toFront(evo) {
        /// <param name="evo" type="Nsb.Classes.Evo">
        /// </param>
        if (this.get_parent() != null) {
            this.element.appendTo(this.get__parentElement$4());
            this.resort(evo);
        }
    },
    
    toBack: function MinionEdit$toBack(evo) {
        /// <param name="evo" type="Nsb.Classes.Evo">
        /// </param>
        if (this.get_parent() != null) {
            this.element.prependTo(this.get__parentElement$4());
            this.resort(evo);
        }
    },
    
    toHigher: function MinionEdit$toHigher(evo) {
        /// <param name="evo" type="Nsb.Classes.Evo">
        /// </param>
        this.element.next(Minion.dotMinionClassName).insertBefore(this.element);
    },
    
    toLower: function MinionEdit$toLower(evo) {
        /// <param name="evo" type="Nsb.Classes.Evo">
        /// </param>
        this.element.prev(Minion.dotMinionClassName).insertAfter(this.element);
    },
    
    resort: function MinionEdit$resort(evo) {
        /// <param name="evo" type="Nsb.Classes.Evo">
        /// </param>
        if (this.get_parent() != null) {
            var md = {};
            this.get__parentElement$4().children(Minion.dotMinionClassName).each(function(i, domEl) {
                var mm = MinionEdit.getMinionFromEl($(domEl));
                md[mm.id] = mm;
            });
            this.get_parent().children = md;
        }
    },
    
    getCss: function MinionEdit$getCss(evo) {
        /// <param name="evo" type="Nsb.Classes.Evo">
        /// </param>
        var name = evo.name;
        evo.value = this.get_data().css[name] || null;
        Inform.debug('GetCss getting {0}={1}', name, evo.value);
    },
    
    setCss: function MinionEdit$setCss(evo) {
        /// <param name="evo" type="Nsb.Classes.Evo">
        /// </param>
        var name = evo.name;
        var css;
        if (typeof(evo.value) === 'string') {
            if ('remove' === evo.value) {
                delete this.get_data().css[name];
                this.element.css(name, '');
                Inform.debug('SetCss removing {0}', name);
                return;
            }
            css = {};
            css[name] = evo.value;
        }
        else {
            css = evo.value;
        }
        $.extend(this.get_data().css, css);
        this.mapCss(this.get_data(), this.element, css);
        Inform.debug('SetCss setting {0}={1}', name, Rx.prettyJson(css));
    }
}


////////////////////////////////////////////////////////////////////////////////
// MiMapActions

MiMapActions = function MiMapActions() {
}
MiMapActions.editMinionProps = function MiMapActions$editMinionProps(evo) {
    /// <param name="evo" type="Nsb.Classes.Evo">
    /// </param>
    var mm = evo.value;
    new Await().addAw(ss.Delegate.create(new EditProps(), new EditProps().editDAw), mm.get_data()).addAw(DomElement.requireResultAw, DomElement.notFail).addDl(function(aw) {
        var result = aw.get_result();
        if (('css' in result)) {
            mm.set_data(result);
        }
        else {
            mm.get_data().css = result;
        }
        new Nsb.Classes.Evo().fireWith(ss.Delegate.create(mm, mm.rePaintAndSave));
    }).commit();
}
MiMapActions.copySlideEv = function MiMapActions$copySlideEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
}


////////////////////////////////////////////////////////////////////////////////
// MiPageGear

MiPageGear = function MiPageGear() {
    /// <field name="_pageGearIsOn" type="Boolean" static="true">
    /// </field>
}
MiPageGear.installPageGear = function MiPageGear$installPageGear() {
    if (MiPageGear._pageGearIsOn) {
        return;
    }
    MiPageGear._pageGearIsOn = true;
    MiPageGear._buildPageGear();
}
MiPageGear._buildPageGear = function MiPageGear$_buildPageGear() {
    new Await().addDx(function() {
        var focused = MinionEdit.get_activeFocus();
        var hasFocus = focused != null;
        var pageGearContainer = $("<div id='PageGearContainer'/>").appendTo(document.body);
        var gearsOuter = $("<div id='GearsBtnOuter' class='GearsBtnOuter'/>").appendTo(pageGearContainer);
        var gear = $("<img id='GearsBtn' class='GearsBtn'/>").attr('src', Uri.img('Common/gear16.gif')).appendTo(gearsOuter);
        var mu = new DDict();
        if (Nsb.Storage.getLocal('CopyBuffer') != null) {
            mu.add('&#9679; Paste to this page', MiPageGear._pasteEv);
        }
        if (hasFocus && Undo.hasPrior(focused.get_partitionKey())) {
            mu.add('&#9679; <b>&#8656; Undo</b> - <small>(ctrl-z)</small>', MiPageGear._undoEv);
        }
        if (hasFocus && Undo.hasNext(focused.get_partitionKey())) {
            mu.add('&#9679; <b>Redo &#8658;</b> - <small>(ctrl-alt-z)</small>', MiPageGear._redoEv);
        }
        mu.add('addablesBar', '<b>Insert</b>').add('&#9679; Text', MiPageGear._addTextItemEv).add('commandsBar', '<b></b>').add('&#9679; Add images', MiPageGear._uploadImgEv).add('&#9679; Manage pages', MiPageGear._pagesEv).add('&#9679; Copy whole page', MiPageGear._copySlideEv).add('&#9679; Change page colors', MiPageGear._colorizeBgEv).add('&#9679; Change page background', MiPageGear._addNewBgEv).add('publishBar', '<b></b>').add('&#9679; Turn curating off', MiPageGear._curatingOffEv);
        new PopMenu().addList(mu.end()).wrapAround(gear).addClass('EditGears');
    }).commit();
}
MiPageGear._redoEv = function MiPageGear$_redoEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    if (MinionEdit.get_focusOrFlash()) {
        MinionEdit.get_activeFocus().redoEv(e);
    }
}
MiPageGear._undoEv = function MiPageGear$_undoEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    if (MinionEdit.get_focusOrFlash()) {
        MinionEdit.get_activeFocus().undoEv(e);
    }
}
MiPageGear._pasteEv = function MiPageGear$_pasteEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    if (MinionEdit.get_canvasOrFlash()) {
        MiCanvasEdit.flashWindowEv(e);
    }
}
MiPageGear._addTextItemEv = function MiPageGear$_addTextItemEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    if (MinionEdit.get_canvasOrFlash()) {
        MiCanvasEdit.flashWindowEv(e);
    }
}
MiPageGear._uploadImgEv = function MiPageGear$_uploadImgEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    if (MinionEdit.get_canvasOrFlash()) {
        MiCanvasEdit.flashWindowEv(e);
    }
}
MiPageGear._pagesEv = function MiPageGear$_pagesEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    if (MinionEdit.get_canvasOrFlash()) {
        MiCanvasEdit.flashWindowEv(e);
    }
}
MiPageGear._copySlideEv = function MiPageGear$_copySlideEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    if (MinionEdit.get_canvasOrFlash()) {
        MiCanvasEdit.flashWindowEv(e);
    }
}
MiPageGear._colorizeBgEv = function MiPageGear$_colorizeBgEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    if (MinionEdit.get_canvasOrFlash()) {
        MiCanvasEdit.flashWindowEv(e);
    }
}
MiPageGear._addNewBgEv = function MiPageGear$_addNewBgEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    if (MinionEdit.get_canvasOrFlash()) {
        MiCanvasEdit.flashWindowEv(e);
    }
}
MiPageGear._curatingOffEv = function MiPageGear$_curatingOffEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    if (MinionEdit.get_canvasOrFlash()) {
        MiCanvasEdit.flashWindowEv(e);
    }
}


////////////////////////////////////////////////////////////////////////////////
// MinionPaste

MinionPaste = function MinionPaste(mm) {
    /// <param name="mm" type="MinionEdit">
    /// The active minion
    /// </param>
    /// <field name="_reIds" type="Object" static="true">
    /// </field>
    /// <field name="_whereTo" type="MinionEdit">
    /// </field>
    /// <field name="_noOffset" type="Boolean">
    /// </field>
    this._whereTo = mm;
}
MinionPaste.copy = function MinionPaste$copy(mm) {
    /// <param name="mm" type="MinionEdit">
    /// </param>
    var md = mm.get_liveData();
    var items = [];
    items.add(md);
    Nsb.Storage.setLocal('CopyBuffer', items);
    Cluster.glassOff();
}
MinionPaste.crossMetrics = function MinionPaste$crossMetrics(to, mm) {
    /// <param name="to" type="Minion">
    /// </param>
    /// <param name="mm" type="Minion">
    /// </param>
    if (mm.get_data().relative && !to.get_data().relative) {
        mm.get_data().offsetParentWidth = to.get_data().dim.width;
        mm.get_data().offsetParentHeight = to.get_data().dim.height;
    }
}
MinionPaste.reIdReset = function MinionPaste$reIdReset() {
    MinionPaste._reIds = {};
}
MinionPaste.reId = function MinionPaste$reId(id) {
    /// <summary>
    /// Generate a new id keeping track of id pairs already generated and reusing them so ids stay in sync
    /// </summary>
    /// <param name="id" type="String">
    /// The old id.
    /// </param>
    /// <returns type="String"></returns>
    if (!(id in MinionPaste._reIds)) {
        MinionPaste._reIds[id] = Formulas.get_newId();
    }
    return MinionPaste._reIds[id];
}
MinionPaste.reIdChildren = function MinionPaste$reIdChildren(md) {
    /// <param name="md" type="Minions.Classes.MinionData">
    /// </param>
    var ids = [];
    if (md.minions != null) {
        var $dict1 = md.minions;
        for (var $key2 in $dict1) {
            var pair = { key: $key2, value: $dict1[$key2] };
            ids.add(pair.key);
            pair.value.id = MinionPaste.reId(pair.value.id);
            md.minions[pair.value.id] = pair.value;
            MinionPaste.reIdChildren(pair.value);
        }
    }
    var $enum3 = ss.IEnumerator.getEnumerator(ids);
    while ($enum3.moveNext()) {
        var id = $enum3.current;
        delete md.minions[id];
    }
}
MinionPaste.prototype = {
    _whereTo: null,
    _noOffset: false,
    
    noOffset: function MinionPaste$noOffset() {
        /// <summary>
        /// Prevents offseting pasted object when it came from the same page.
        /// </summary>
        /// <returns type="MinionPaste"></returns>
        this._noOffset = true;
        return this;
    },
    
    pasteEv: function MinionPaste$pasteEv(e) {
        /// <summary>
        /// Pastes from an event.
        /// </summary>
        /// <param name="e" type="jQueryEvent">
        /// The event.
        /// </param>
        this.paste(Nsb.Storage.getLocal('CopyBuffer'));
    },
    
    paste: function MinionPaste$paste(grplst) {
        /// <param name="grplst" type="Array">
        /// </param>
        if (grplst != null) {
            MinionPaste.reIdReset();
            if (typeof(grplst) === 'string') {
                grplst = JSON.parse(grplst);
            }
            if (!$.isArray(grplst)) {
                grplst = [grplst];
            }
            var awx = new Await();
            if (grplst.length === 1) {
                var md = grplst[0];
                md.groupId = null;
                md.parentId = null;
                md.clusterId = null;
            }
            var $enum1 = ss.IEnumerator.getEnumerator(grplst);
            while ($enum1.moveNext()) {
                var item = $enum1.current;
                this._pasteClosure(awx, item);
            }
            awx.addDx(function() {
                Nsb.Storage.setLocal('CopyBuffer', grplst);
            });
            awx.commit();
        }
    },
    
    _pasteClosure: function MinionPaste$_pasteClosure(awp, item) {
        /// <param name="awp" type="Await">
        /// </param>
        /// <param name="item" type="Minions.Classes.MinionData">
        /// </param>
        awp.addDl(ss.Delegate.create(this, function(aw) {
            this.pasteAw(aw, item);
        }));
    },
    
    pasteAw: function MinionPaste$pasteAw(awp, md) {
        /// <summary>
        /// Pastes an item to the active location.
        /// </summary>
        /// <param name="awp" type="Await">
        /// The awp.
        /// </param>
        /// <param name="md" type="Minions.Classes.MinionData">
        /// The MinionData.
        /// </param>
        if (!this._noOffset && $('#' + md.id, this._whereTo.absoluteParent().element).length > 0) {
            md.pos.top += 20;
        }
        md.id = MinionPaste.reId(md.id);
        if (md.parentId != null) {
            md.parentId = MinionPaste.reId(md.parentId);
        }
        if (md.groupId != null) {
            md.groupId = MinionPaste.reId(md.groupId);
        }
        if (md.clusterId != null) {
            md.clusterId = MinionPaste.reId(md.clusterId);
        }
        MinionPaste.reIdChildren(md);
        var mm = this._whereTo.newMinion(this._whereTo.get_topMinion()).setData(md);
        MinionPaste.crossMetrics(this._whereTo, mm);
        mm.addTo(this._whereTo).paint();
        mm.resizeFixedMetrics(this._whereTo);
        var tmd = this._whereTo.get_data();
        if (tmd.actions != null && tmd.actions.paste != null) {
            try {
                var fn = eval(tmd.actions.paste);
                fn(mm, tmd);
            }
            catch (ex) {
                Inform.error('Failed paste action: {0}', ex);
            }
        }
        awp.done();
    }
}


////////////////////////////////////////////////////////////////////////////////
// MiPopChoice

MiPopChoice = function MiPopChoice(e, pos, choices) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    /// <param name="pos" type="Minions.Classes.Pos">
    /// </param>
    /// <param name="choices" type="Object">
    /// </param>
    /// <field name="_choices$4" type="Object">
    /// </field>
    /// <field name="_e$4" type="jQueryEvent">
    /// </field>
    /// <field name="_ul$4" type="jQueryObject">
    /// </field>
    /// <field name="_cancelEv$4" type="Function">
    /// </field>
    /// <field name="_basicCss$4" type="String" static="true">
    /// </field>
    MiPopChoice.initializeBase(this);
    this._e$4 = e;
    this._choices$4 = choices;
    this.element.addClass('MiPopChoice');
    this._ul$4 = $('<ul/>').appendTo(this.element);
    this.element.css({ top: pos.top, left: pos.left });
    var $dict1 = this._choices$4;
    for (var $key2 in $dict1) {
        var pair = { key: $key2, value: $dict1[$key2] };
        this._buildClosure$4(pair.key, pair.value);
    }
}
MiPopChoice.prototype = {
    _choices$4: null,
    _e$4: null,
    _ul$4: null,
    _cancelEv$4: null,
    
    css: function MiPopChoice$css(css) {
        /// <param name="css" type="Object">
        /// </param>
        /// <returns type="MiPopChoice"></returns>
        this.element.css(css);
        return this;
    },
    
    setCancel: function MiPopChoice$setCancel(fn) {
        /// <param name="fn" type="Function">
        /// </param>
        /// <returns type="MiPopChoice"></returns>
        this._cancelEv$4 = fn;
        return this;
    },
    
    cancelEv: function MiPopChoice$cancelEv(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        if (this._cancelEv$4 != null) {
            this._cancelEv$4(e);
        }
        MiPopChoice.callBaseMethod(this, 'cancelEv', [ e ]);
    },
    
    _buildClosure$4: function MiPopChoice$_buildClosure$4(key, fn) {
        /// <param name="key" type="String">
        /// </param>
        /// <param name="fn" type="Function">
        /// </param>
        $('<li/>').appendTo(this._ul$4).append($("<input type='radio'/>").click(ss.Delegate.create(this, function(e) {
            this.destroy(e);
            fn(e);
        }))).append($('<a/>').html(key).click(ss.Delegate.create(this, function(e) {
            this.destroy(e);
            fn(e);
        })));
    }
}


////////////////////////////////////////////////////////////////////////////////
// MiUiOp

MiUiOp = function MiUiOp() {
    /// <field name="_fromId" type="String" static="true">
    /// </field>
    /// <field name="cancelled" type="Boolean" static="true">
    /// </field>
    /// <field name="_e" type="jQueryEvent" static="true">
    /// </field>
    /// <field name="_ui" type="jQueryUiObject" static="true">
    /// </field>
    /// <field name="_active" type="Boolean" static="true">
    /// </field>
    /// <field name="_queRestore" type="Boolean" static="true">
    /// </field>
    /// <field name="_onAbort" type="Function" static="true">
    /// </field>
    /// <field name="_snapshot" type="String" static="true">
    /// </field>
}
MiUiOp.get_theMinion = function MiUiOp$get_theMinion() {
    /// <value type="MinionEdit"></value>
    return MinionEdit.getMinionById(MiUiOp._fromId);
}
MiUiOp.get_snapshot = function MiUiOp$get_snapshot() {
    /// <value type="String"></value>
    return MiUiOp._snapshot;
}
MiUiOp.init = function MiUiOp$init(mm, e, ui) {
    /// <param name="mm" type="MinionEdit">
    /// </param>
    /// <param name="e" type="jQueryEvent">
    /// </param>
    /// <param name="ui" type="jQueryUiObject">
    /// </param>
    if (MiUiOp._active) {
        debugger;
    }
    MiUiOp._active = true;
    MiUiOp._queRestore = false;
    MiUiOp._onAbort = null;
    MiUiOp._e = e || null;
    MiUiOp._ui = ui || null;
    MiUiOp.cancelled = false;
    MiUiOp._fromId = mm.id;
    MiUiOp._snapshot = mm.get_snapShot();
}
MiUiOp.setCancel = function MiUiOp$setCancel(fn) {
    /// <param name="fn" type="Function">
    /// </param>
    MiUiOp._onAbort = fn;
}
MiUiOp.finish = function MiUiOp$finish() {
    MiUiOp._active = false;
    if (MiUiOp._queRestore) {
        MiUiOp.restore();
    }
}
MiUiOp.cancel = function MiUiOp$cancel() {
    MiUiOp.cancelled = true;
}
MiUiOp.abortEv = function MiUiOp$abortEv(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    Inform.debug('MiUiOp.Abort()');
    MiUiOp.cancel();
    if (MiUiOp._active) {
        MiUiOp._queRestore = true;
    }
    if (MiUiOp._onAbort != null) {
        MiUiOp._onAbort(e);
        MiUiOp._onAbort = null;
    }
}
MiUiOp.restore = function MiUiOp$restore() {
    MiUiOp.get_theMinion().restoreFrom(MiUiOp._snapshot);
}


////////////////////////////////////////////////////////////////////////////////
// MinionsEdit.Classes.Pages

MinionsEdit.Classes.Pages = function MinionsEdit_Classes_Pages() {
    /// <field name="_outerId$3" type="String" static="true">
    /// </field>
    /// <field name="_optsKey$3" type="String" static="true">
    /// </field>
    /// <field name="_instance$3" type="MinionsEdit.Classes.Pages" static="true">
    /// </field>
    /// <field name="_dragger$3" type="jQueryObject">
    /// </field>
    /// <field name="_opts$3" type="MinionsEdit.Classes.PageMgrOpts">
    /// </field>
    /// <field name="_outer$3" type="jQueryObject">
    /// </field>
    /// <field name="_pageList$3" type="jQueryObject">
    /// </field>
    /// <field name="_asking$3" type="Boolean">
    /// </field>
    /// <field name="_pages$3" type="PagesD">
    /// </field>
    /// <field name="_lastDrag$3" type="jQueryObject">
    /// </field>
    /// <field name="_dragging$3" type="String">
    /// </field>
    /// <field name="_dragover$3" type="String">
    /// </field>
    /// <field name="_dragOn$3" type="Boolean">
    /// </field>
    MinionsEdit.Classes.Pages.initializeBase(this);
    MinionsEdit.Classes.Pages._instance$3 = this;
    this._opts$3 = Nsb.Storage.getLocal('PageMgrOpts') || new MinionsEdit.Classes.PageMgrOpts();
    Cluster.glass(ss.Delegate.create(this, this._cancelEv$3)).css('background', 'rgba(0,0,0,.55)');
    this._outer$3 = $("<div id='" + 'PageManager' + "' class='AboveHider'/>").appendTo(document.body);
    this._dragger$3 = $("<div class='Dragger'/>").appendTo(this._outer$3);
    this._outer$3.draggable({ stop: ss.Delegate.create(this, this._readSavePos$3), handle: this._dragger$3 });
    this._pageList$3 = $("<div class='pageList'/>").appendTo(this._outer$3);
    var menu = $("<div class='Menu'/>").appendTo(this._outer$3);
    this._createMenu$3(menu);
    $("<button class='cancel'/>").attr('title', ThemeMinions.pageCancelBtnTitle).html('cancel').appendTo(this._outer$3).click(ss.Delegate.create(this, this._cancelEv$3));
    $(document).bind('keydown.Pages', ss.Delegate.create(this, function(e) {
        Keys.escKey(e, ss.Delegate.create(this, this._closeEv$3));
    }));
    Keys.docKeyDown('.Pages', 78, true, ss.Delegate.create(this, this._newPageEv$3));
    Keys.docKeyDown('.Pages', 13, true, ss.Delegate.create(this, this._saveAndCloseEv$3));
    if (!this._opts$3.pos.top) {
        this._outer$3.position({ my: 'top center', at: 'top center', of: window.self, offset: '0 -200', collision: 'fit fit' });
        this._readSavePos$3();
    }
    else {
        this._outer$3.css({ top: this._opts$3.pos.top + document.body.scrollTop, left: this._opts$3.pos.left + document.body.scrollLeft });
    }
    Keys.filterAll(this._outer$3);
    $(document).bind('Asking.Pages', ss.Delegate.create(this, function() {
        this._asking$3 = true;
    }));
    $(document).bind('AskingDone.Pages', ss.Delegate.create(this, function() {
        this._asking$3 = false;
    }));
    DomElement.focusElementAw(Await.get_asyncAw(), this._pageList$3);
}
MinionsEdit.Classes.Pages.Ev = function MinionsEdit_Classes_Pages$Ev(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    DomElement.cancelEvent(e);
    if (MinionsEdit.Classes.Pages._instance$3 != null) {
        return;
    }
    ThemeYoshi.supressCurateEvents = true;
    var pgs = new MinionsEdit.Classes.Pages();
    new Await().addAw(FileBlobBase.retrieveBlobStringAw, ThemeYoshi.pagesPartition, ThemeYoshi.pagesRowKey).handleDl(Exceptions.blobLoadError, Await.abortAw).addDl(function(aw) {
        pgs._pages$3 = JSON.parse(aw.get_result());
        pgs._build$3();
        if (ThemeYoshi.pages == null) {
            ThemeYoshi.pages = pgs._pages$3;
        }
        $("<button class='done DeefBtn'/>").attr('title', ThemeMinions.pageAddDoneTitle).html('done').appendTo(pgs._outer$3).click(ss.Delegate.create(pgs, pgs._saveAndCloseEv$3));
        $("<button class='add'/>").attr('title', ThemeMinions.pageAddBtnTitle).html('+').appendTo(pgs._outer$3).click(ss.Delegate.create(pgs, pgs._newPageEv$3));
    }).commit();
}
MinionsEdit.Classes.Pages.prototype = {
    _dragger$3: null,
    _opts$3: null,
    _outer$3: null,
    _pageList$3: null,
    _asking$3: false,
    _pages$3: null,
    
    _createMenu$3: function MinionsEdit_Classes_Pages$_createMenu$3(menu) {
        /// <param name="menu" type="jQueryObject">
        /// </param>
        $("<div class='Choice'/>").appendTo(menu).html('&#9679; Add images').click(function() {
            Nsb.Classes.Evo.trigger('UploadImgEv');
        });
        if (ThemeBase.godMode) {
            $('<hr/>').appendTo(menu);
            $("<div class='Choice'/>").appendTo(menu).html('&#9679; Collect images').click(ss.Delegate.create(this, this.collectImagesEv));
        }
    },
    
    _build$3: function MinionsEdit_Classes_Pages$_build$3() {
        var table = $('<table/>').appendTo(this._pageList$3);
        var body = $('<tbody/>').appendTo(table);
        $('<tr/>').appendTo(body).append($("<th class='page'/>").html('page')).append($("<th class='dragger'/>").html('order')).append($("<th class='visible'/>").html('public')).append($("<th class='del'/>").html('del'));
        var $dict1 = this._pages$3.pages;
        for (var $key2 in $dict1) {
            var pg = { key: $key2, value: $dict1[$key2] };
            var row = $('<tr/>').appendTo(body);
            var linkFace = pg.value.Face || pg.value.Name;
            var pageName = pg.value.Name || 'page';
            var isSpecial = pageName === ThemeYoshi.defaultPageName || pageName === ThemeYoshi.adminPageName;
            var lnk = $('<a/>').attr('href', Uri.addPair(Uri.path(window.location.href), 'page', pageName)).html(Transform.htmlize(linkFace)).appendTo(this._pageList$3);
            if (ThemeYoshi.currentPageName === pageName) {
                row.addClass('CurrentPage');
            }
            $("<td class='page'/>").appendTo(row).append(lnk);
            var dragger = $("<td class='dragger Center'/>").appendTo(row);
            if (!isSpecial) {
                dragger.append($("<div style='cursor:pointer;font-size:100%' title='drag to reorder'>" + ThemeBase.dragOrder + '</div>')).click(this._adminClosure$3(pg.value));
            }
            else {
                dragger.append('&nbsp;');
            }
            var visible = $("<input type='checkbox'/>");
            visible.attr({ checked: pg.value.Visible }).click(this._hiderClosure$3(pg.value, visible));
            var shower = $("<td class='showpg'/>").appendTo(row);
            if (!isSpecial) {
                shower.append(visible);
            }
            else if (pageName === ThemeYoshi.defaultPageName) {
                shower.append(String.format("<span style='font-size:120%'>{0}</span>", ThemeBase.ballotBoxChecked));
            }
            else {
                shower.append(String.format("<span style='font-size:120%'>{0}</span>", ThemeBase.ballotBox));
            }
            var td = $("<td class='del Center'/>").appendTo(row);
            if (!isSpecial) {
                td.append($("<div class='del' style='color:rgba(128,0,0,.65);cursor:pointer;' title='delete this page'/>").html('\u2716').mouseenter(Helpers.closureEv(function(e, tdd) {
                    tdd.css('background-color', 'rgba(255,0,0,.25)');
                }, td)).mouseleave(Helpers.closureEv(function(e, tdd) {
                    tdd.css('background-color', '');
                }, td)).click(this._delClosure$3(pg.value)));
                this._addDraggable$3(row, dragger, pg.value.Name, linkFace);
            }
            else {
                td.html('&nbsp;');
            }
        }
    },
    
    _lastDrag$3: null,
    _dragging$3: null,
    _dragover$3: null,
    _dragOn$3: false,
    
    _addDraggable$3: function MinionsEdit_Classes_Pages$_addDraggable$3(row, dragger, name, face) {
        /// <param name="row" type="jQueryObject">
        /// </param>
        /// <param name="dragger" type="jQueryObject">
        /// </param>
        /// <param name="name" type="String">
        /// </param>
        /// <param name="face" type="String">
        /// </param>
        this._dragover$3 = this._dragging$3 = null;
        this._lastDrag$3 = null;
        row.draggable({ handle: dragger, helper: function() {
            return $("<div class='draghelper'/>").html(face);
        }, start: ss.Delegate.create(this, function() {
            this._dragging$3 = name;
        }), stop: ss.Delegate.create(this, this._dropPageEv$3) });
        row.bind('mouseenter', ss.Delegate.create(this, function(e) {
            if (this._dragging$3 != null) {
                this._lastDrag$3 = $(e.target).closest('tr');
                this._lastDrag$3.addClass('DragOver');
                this._dragover$3 = this._lastDrag$3.data('dropkey');
            }
        })).bind('mouseleave', ss.Delegate.create(this, function(e) {
            $(e.target).closest('tr').removeClass('DragOver');
            this._dragover$3 = null;
        })).data('dropkey', name);
    },
    
    _dropPageEv$3: function MinionsEdit_Classes_Pages$_dropPageEv$3(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        if (this._dragover$3 == null || this._dragover$3 === ThemeYoshi.defaultPageName || this._dragover$3 === this._dragging$3) {
            if (this._lastDrag$3 != null) {
                this._lastDrag$3.removeClass('DragOver');
            }
            this._dragging$3 = this._dragover$3 = null;
            return;
        }
        Inform.debug('Dropping {0} on {1}', this._dragging$3, this._dragover$3);
        var pages = {};
        var $dict1 = this._pages$3.pages;
        for (var $key2 in $dict1) {
            var pp = { key: $key2, value: $dict1[$key2] };
            if (pp.value.Name === this._dragging$3) {
                continue;
            }
            if (pp.value.Name === this._dragover$3) {
                pages[this._dragging$3] = this._pages$3.pages[this._dragging$3];
            }
            pages[pp.key] = pp.value;
        }
        this._dragging$3 = this._dragover$3 = null;
        this._pages$3.pages = pages;
        ThemeYoshi.pages.pages = pages;
        this._pageList$3.empty();
        this._build$3();
        this._saveAw$3(Await.get_asyncAw());
    },
    
    _readSavePos$3: function MinionsEdit_Classes_Pages$_readSavePos$3() {
        this._opts$3.pos = this._outer$3.offset();
        var p = this._opts$3.pos;
        p.top -= document.body.scrollTop;
        p.left -= document.body.scrollLeft;
        Nsb.Storage.setLocal('PageMgrOpts', this._opts$3);
    },
    
    _hiderClosure$3: function MinionsEdit_Classes_Pages$_hiderClosure$3(pg, el) {
        /// <param name="pg" type="PageD">
        /// </param>
        /// <param name="el" type="jQueryObject">
        /// </param>
        /// <returns type="Function"></returns>
        return ss.Delegate.create(this, function() {
            window.setTimeout(ss.Delegate.create(this, function() {
                pg.Visible = el.is(':checked');
                this._saveAw$3(Await.get_asyncAw());
            }), 1);
        });
    },
    
    _adminClosure$3: function MinionsEdit_Classes_Pages$_adminClosure$3(pg) {
        /// <param name="pg" type="PageD">
        /// </param>
        /// <returns type="Function"></returns>
        return ss.Delegate.create(this, function(e) {
            window.setTimeout(ss.Delegate.create(this, function() {
                if (e.shiftKey) {
                    pg.Admin = !pg.Admin;
                    this._saveAw$3(Await.get_asyncAw());
                }
            }), 1);
        });
    },
    
    _delClosure$3: function MinionsEdit_Classes_Pages$_delClosure$3(pg) {
        /// <param name="pg" type="PageD">
        /// </param>
        /// <returns type="Function"></returns>
        var fnarg = 'Pages.DelClosure';
        return ss.Delegate.create(this, function(e) {
            var awx = new Await();
            if (!e.altKey) {
                awx.addAw(ss.Delegate.create(new Ask(), new Ask().okCancelAw), ThemeYoshi.forSure).addAw(DomElement.requireResultAw, true);
            }
            awx.addDx(ss.Delegate.create(this, function() {
                delete this._pages$3.pages[pg.Name];
                this._pageList$3.empty();
                this._build$3();
                Inform.event(fnarg, pg.Name);
            })).addAw(ss.Delegate.create(this, this._saveAw$3)).addAw(FileBlobBase.emptyFolderAw, Uri.join('pg/gigs', pg.Name || 'aXSAFEXa'), true).commit();
        });
    },
    
    _saveAw$3: function MinionsEdit_Classes_Pages$_saveAw$3(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        Uri.bumpVersion();
        var output = Rx.prettyJson(this._pages$3);
        new Await().addAw(FileBlobBase.storeBlobStringAw, { partitionKey: ThemeYoshi.pagesPartition, rowKey: ThemeYoshi.pagesRowKey, content: output, backup: true }).commit(awp);
    },
    
    _saveAndCloseEv$3: function MinionsEdit_Classes_Pages$_saveAndCloseEv$3(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        new Await().addAw(ss.Delegate.create(this, this._saveAw$3)).addDx(ss.Delegate.create(this, function() {
            this._closeEv$3(e);
            ThemeYoshi.reloadPage();
        })).commit();
    },
    
    _newPageEv$3: function MinionsEdit_Classes_Pages$_newPageEv$3(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        var fnarg = 'Pages.NewPageEv';
        DomElement.cancelEvent(e);
        var newName;
        new Await().addAw(ss.Delegate.create(new Ask(), new Ask().textAw), { Msg: "Title for new page<br><font size='-1'>shown in links and tabs</font>" }).addAw(DomElement.requireResultAw, DomElement.notFailOrEmpty).addDx(ss.Delegate.create(this, function(aw) {
            newName = (aw.get_result()).trim();
            var safeName = Strings.safeFileName(newName);
            var pg = new PageD();
            pg.Name = safeName;
            pg.Face = newName;
            pg.Visible = false;
            this._pages$3.pages[safeName] = pg;
            this._pageList$3.empty();
            this._build$3();
            this._saveAw$3(Await.get_asyncAw());
            Inform.event(fnarg, safeName);
        })).commit();
    },
    
    _cancelEv$3: function MinionsEdit_Classes_Pages$_cancelEv$3(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        this._closeEv$3(e);
    },
    
    _closeEv$3: function MinionsEdit_Classes_Pages$_closeEv$3(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        if (this._asking$3) {
            return;
        }
        MinionsEdit.Classes.Pages._instance$3 = null;
        ThemeYoshi.supressCurateEvents = false;
        Keys.docKeyReleaseAll('.Pages');
        this._outer$3.remove();
        DomElement.cancelEvent(e);
        Cluster.glassOff(true);
    },
    
    collectImagesEv: function MinionsEdit_Classes_Pages$collectImagesEv(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        var imgs = $('img');
        var awx = new Await();
        awx.addAw(ImageManager.clearThumbsAw);
        imgs.each(function(i, domEl) {
            var t = $(domEl);
            var src = t.attr('src');
            if (!src.indexOf(ThemeBase.mediaImgUri + '/')) {
                return true;
            }
            awx.addAw(ImageManager.updateImageDataAw, src);
            return true;
        });
        awx.loadAndDo(Uri.scripts('Scripts/PhotoUpload.js'), 'PhotoUploadViewer.UpdateDirImagesEv', { Path: 'pg/images' }, e);
        awx.commit();
    }
}


////////////////////////////////////////////////////////////////////////////////
// MinionsEdit.Classes.PageMgrOpts

MinionsEdit.Classes.PageMgrOpts = function MinionsEdit_Classes_PageMgrOpts() {
    /// <field name="pos" type="Minions.Classes.Pos">
    /// </field>
    this.pos = { Top: 0, Left: 0 };
}


////////////////////////////////////////////////////////////////////////////////
// TinyPopup

TinyPopup = function TinyPopup() {
    /// <field name="_css$3" type="String" static="true">
    /// </field>
    TinyPopup.initializeBase(this);
    Cluster.hider(true);
    this.element = $('<div/>').addClass('TinyPopup AboveHider WhiteGradiant').css({ position: 'absolute' }).appendTo($(document.body));
    $(document).bind('keydown.TinyPopup', ss.Delegate.create(this, this.keysEv));
}
TinyPopup.prototype = {
    
    destroy: function TinyPopup$destroy(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        this.element.remove();
        Cluster.hider(false);
        $(document).unbind('.TinyPopup');
    },
    
    keysEv: function TinyPopup$keysEv(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        if (e.which === 27) {
            this.cancelEv(e);
        }
    },
    
    cancelEv: function TinyPopup$cancelEv(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        Inform.debug('TinyPopup.CancelEv()');
        this.destroy(e);
    }
}


////////////////////////////////////////////////////////////////////////////////
// MinionsEdit.Classes.UndoItem

MinionsEdit.Classes.UndoItem = function MinionsEdit_Classes_UndoItem(buffer) {
    /// <param name="buffer" type="String">
    /// </param>
    /// <field name="buffer" type="String">
    /// </field>
    this.buffer = buffer;
}
MinionsEdit.Classes.UndoItem.parse = function MinionsEdit_Classes_UndoItem$parse(content) {
    /// <param name="content" type="String">
    /// </param>
    /// <returns type="Array"></returns>
    try {
        return JSON.parse(content);
    }
    catch ($e1) {
        return null;
    }
}
MinionsEdit.Classes.UndoItem.prototype = {
    buffer: null
}


MiProperty.registerClass('MiProperty', Cluster);
MinionsEdit.Classes._miWidgetCss.registerClass('MinionsEdit.Classes._miWidgetCss');
MiEnumWidget.registerClass('MiEnumWidget', MiProperty);
MiSelectWidget.registerClass('MiSelectWidget', MiProperty);
MiColorWidget.registerClass('MiColorWidget', MiProperty);
MiBorderWidthWidget.registerClass('MiBorderWidthWidget', MiEnumWidget);
MiBorderStyleWidget.registerClass('MiBorderStyleWidget', MiSelectWidget);
MiBorderRadius.registerClass('MiBorderRadius', MiSelectWidget);
MiAlphaWidget.registerClass('MiAlphaWidget', MiSelectWidget);
MiFontSizeWidget.registerClass('MiFontSizeWidget', MiEnumWidget);
MiPxWidget.registerClass('MiPxWidget', MiSelectWidget);
MiPropPage.registerClass('MiPropPage', Cluster);
NColor.registerClass('NColor');
MinionsEdit.Classes.MiColorPicker.registerClass('MinionsEdit.Classes.MiColorPicker');
PanelPopup.registerClass('PanelPopup', Actor);
EditProps.registerClass('EditProps', Ask);
MinionsEdit.Classes.EvoEvents.registerClass('MinionsEdit.Classes.EvoEvents');
MiDrop.registerClass('MiDrop');
MiPropPanel.registerClass('MiPropPanel', PanelPopup);
MiKeyMap.registerClass('MiKeyMap');
MiMask.registerClass('MiMask');
MinionEdit.registerClass('MinionEdit', Minion);
MiCanvasEdit.registerClass('MiCanvasEdit', MinionEdit);
MiMetrics.registerClass('MiMetrics');
MiMapActions.registerClass('MiMapActions');
MiPageGear.registerClass('MiPageGear');
MinionPaste.registerClass('MinionPaste');
TinyPopup.registerClass('TinyPopup', Actor);
MiPopChoice.registerClass('MiPopChoice', TinyPopup);
MiUiOp.registerClass('MiUiOp');
MinionsEdit.Classes.Pages.registerClass('MinionsEdit.Classes.Pages', Actor);
MinionsEdit.Classes.PageMgrOpts.registerClass('MinionsEdit.Classes.PageMgrOpts');
MinionsEdit.Classes.UndoItem.registerClass('MinionsEdit.Classes.UndoItem');
MiProperty.defaultCss = { 'border-color': 'rgba(0,0,0,1)' };
MiProperty._opacityList$2 = null;
MiProperty._alphaValues$2 = null;
(function () {
    DomElement.addStyle('\r\n.MiProperty {\r\n    position: relative;\r\n    display: block;\r\n}\r\n        ');
})();
(function () {
    DomElement.addStyle('\r\n.MiColorPicker {\r\n    display: inline-block;\r\n    margin: 0 3px;\r\n    vertical-align: top;\r\n}\r\n.MiEPEnum {\r\n    clear: both;\r\n    position: relative;\r\n    display: block;\r\n}\r\n.MiEPEnum div {\r\n    display: inline-block;\r\n    padding: 0 1px;\r\n    border: 1px solid transparent;\r\n    vertical-align: top;\r\n}\r\n.MiEPEnum div:hover {\r\n    padding: 0 1px;\r\n    border: 1px solid green;\r\n    cursor: default;\r\n}\r\n.MiEPEnum div.MiEPBorderSelect {\r\n    border: 1px solid #FFD700;\r\n}\r\n.MiEPSelect {\r\n    clear: both;\r\n    position: relative;\r\n    display: block;\r\n}\r\n        ');
})();
(function () {
    DomElement.addStyle('\r\n.MiEPPage {\r\n    display: block;\r\n    postion: absolute;\r\n    top: 0;\r\n    left: 0;\r\n    right: 0;\r\n    bottom: 0;\r\n}\r\n.MiEPEnder {\r\n    display: block;\r\n    clear: both;\r\n    width: 1px;\r\n    height: 10px;\r\n}\r\n.MiEPBox {\r\n    display: inline-block;\r\n    clear: both;\r\n    width: 120px;\r\n    min-height: 120px;\r\n    vertical-align: top;\r\n}\r\n.MiEPLabel {\r\n    color: lightblue;\r\n    font-weight: bold;\r\n    text-align: center;\r\n    margin: 5px 0 2px 0;\r\n}\r\n        ');
})();
MinionsEdit.Classes.MiColorPicker.pickerCss = '\r\n/* Color Pickier */\r\n.ClrSwa {\r\n    position: relative;\r\n    margin: 1px;\r\n    padding: 0px;\r\n    width: 10px;\r\n    height: 10px;\r\n    border: 2px solid black;\r\n}\r\n\r\n.ClrSwa:hover {\r\n    border: 2px solid gold;\r\n}\r\n\r\n.Transparent {\r\n    color: #CCC;\r\n    background: transparent;\r\n    float: right;\r\n    border: 2px solid transparent;\r\n}\r\n\r\n.Transparent:hover {\r\n    border: 2px solid gold;\r\n}\r\n\r\n.BorderZero {\r\n    color: gold;\r\n}\r\n';
MinionsEdit.Classes.MiColorPicker.html = '\r\n<table cellspacing="0" cellpadding="0">\r\n    <tbody>\r\n        <tr>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(255, 255, 255);" title="rgb(255, 255, 255)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(204, 204, 204);" title="rgb(204, 204, 204)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(192, 192, 192);" title="rgb(192, 192, 192)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(153, 153, 153);" title="rgb(153, 153, 153)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(102, 102, 102);" title="rgb(102, 102, 102)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(51, 51, 51);" title="rgb(51, 51, 51)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(0, 0, 0);" title="rgb(0, 0, 0)">\r\n                </div>\r\n            </td>\r\n        </tr>\r\n        <tr>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(255, 204, 204);" title="rgb(255, 204, 204)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(255, 102, 102);" title="rgb(255, 102, 102)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(255, 0, 0);" title="rgb(255, 0, 0)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(204, 0, 0);" title="rgb(204, 0, 0)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(153, 0, 0);" title="rgb(153, 0, 0)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(102, 0, 0);" title="rgb(102, 0, 0)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(51, 0, 0);" title="rgb(51, 0, 0)">\r\n                </div>\r\n            </td>\r\n        </tr>\r\n        <tr>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(255, 204, 153);" title="rgb(255, 204, 153)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(255, 153, 102);" title="rgb(255, 153, 102)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(255, 153, 0);" title="rgb(255, 153, 0)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(255, 102, 0);" title="rgb(255, 102, 0)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(204, 102, 0);" title="rgb(204, 102, 0)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(153, 51, 0);" title="rgb(153, 51, 0)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(102, 51, 0);" title="rgb(102, 51, 0)">\r\n                </div>\r\n            </td>\r\n        </tr>\r\n        <tr>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(255, 255, 153);" title="rgb(255, 255, 153)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(255, 255, 102);" title="rgb(255, 255, 102)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(255, 204, 102);" title="rgb(255, 204, 102)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(255, 204, 51);" title="rgb(255, 204, 51)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(204, 153, 51);" title="rgb(204, 153, 51)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(153, 102, 51);" title="rgb(153, 102, 51)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(102, 51, 51);" title="rgb(102, 51, 51)">\r\n                </div>\r\n            </td>\r\n        </tr>\r\n        <tr>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(255, 255, 204);" title="rgb(255, 255, 204)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(255, 255, 51);" title="rgb(255, 255, 51)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(255, 255, 0);" title="rgb(255, 255, 0)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(255, 204, 0);" title="rgb(255, 204, 0)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(153, 153, 0);" title="rgb(153, 153, 0)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(102, 102, 0);" title="rgb(102, 102, 0)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(51, 51, 0);" title="rgb(51, 51, 0)">\r\n                </div>\r\n            </td>\r\n        </tr>\r\n        <tr>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(153, 255, 153);" title="rgb(153, 255, 153)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(102, 255, 153);" title="rgb(102, 255, 153)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(51, 255, 51);" title="rgb(51, 255, 51)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(51, 204, 0);" title="rgb(51, 204, 0)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(0, 153, 0);" title="rgb(0, 153, 0)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(0, 102, 0);" title="rgb(0, 102, 0)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(0, 51, 0);" title="rgb(0, 51, 0)">\r\n                </div>\r\n            </td>\r\n        </tr>\r\n        <tr>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(153, 255, 255);" title="rgb(153, 255, 255)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(51, 255, 255);" title="rgb(51, 255, 255)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(102, 204, 204);" title="rgb(102, 204, 204)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(0, 204, 204);" title="rgb(0, 204, 204)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(51, 153, 153);" title="rgb(51, 153, 153)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(51, 102, 102);" title="rgb(51, 102, 102)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(0, 51, 51);" title="rgb(0, 51, 51)">\r\n                </div>\r\n            </td>\r\n        </tr>\r\n        <tr>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(204, 255, 255);" title="rgb(204, 255, 255)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(102, 255, 255);" title="rgb(102, 255, 255)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(51, 204, 255);" title="rgb(51, 204, 255)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(51, 102, 255);" title="rgb(51, 102, 255)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(51, 51, 255);" title="rgb(51, 51, 255)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(0, 0, 153);" title="rgb(0, 0, 153)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(0, 0, 102);" title="rgb(0, 0, 102)">\r\n                </div>\r\n            </td>\r\n        </tr>\r\n        <tr>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(204, 204, 255);" title="rgb(204, 204, 255)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(153, 153, 255);" title="rgb(153, 153, 255)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(102, 102, 204);" title="rgb(102, 102, 204)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(102, 51, 255);" title="rgb(102, 51, 255)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(102, 0, 204);" title="rgb(102, 0, 204)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(51, 51, 153);" title="rgb(51, 51, 153)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(51, 0, 153);" title="rgb(51, 0, 153)">\r\n                </div>\r\n            </td>\r\n        </tr>\r\n        <tr>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(255, 204, 255);" title="rgb(255, 204, 255)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(255, 153, 255);" title="rgb(255, 153, 255)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(204, 102, 204);" title="rgb(204, 102, 204)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(204, 51, 204);" title="rgb(204, 51, 204)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(153, 51, 153);" title="rgb(153, 51, 153)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(102, 51, 102);" title="rgb(102, 51, 102)">\r\n                </div>\r\n            </td>\r\n            <td>\r\n                <div class="ClrSwa" style="background-color: rgb(51, 0, 51);" title="rgb(51, 0, 51)">\r\n                </div>\r\n            </td>\r\n        </tr>\r\n    </tbody>\r\n</table>\r\n';
(function () {
    DomElement.addStyle('\r\n        .PanelPopup {\r\n            position: absolute;\r\n            width: 500px;\r\n            background-color: rgba(0,0,0,.65);\r\n            border: 1px solid white;\r\n            -moz-border-radius: 8px;\r\n            -webkit-border-radius: 8px;\r\n            border-radius: 8px;\r\n        }\r\n        ');
})();
MinionsEdit.Classes.EvoEvents.redrawPageGear = 'RedrawPageGear';
MinionsEdit.Classes.EvoEvents.onPageSave = 'OnPageSave';
MinionsEdit.Classes.EvoEvents.setPageHeight = 'SetPageHeight';
MiDrop._dropOptions = { accept: Minion.dotMinionClassName, over: MiDrop._dropOverEv, out: MiDrop._dropOutEv, drop: MiDrop._dropDropEv, tolerance: 'pointer', hoverClass: 'DropOver', greedy: true };
MiDrop._toId = null;
MiDrop._ui = null;
MiPropPanel._currentTabIdx$4 = 0;
MiPropPanel._instance$4 = null;
(function () {
    DomElement.addStyle('\r\n.MiEditPanel {\r\n    width: 360px;\r\n    min-height: 180px;\r\n    background-color: rgba(0,0,0,.85);\r\n    border: 1px solid white;\r\n    font-family: calibri,arial;\r\n    font-size: 10pt;\r\n    line-height: 100%;\r\n    -moz-border-radius: 8px;\r\n    -webkit-border-radius: 8px;\r\n    border-radius: 8px;\r\n}\r\n.MiEPLeft {\r\n    position: absolute;\r\n    top: 5px;\r\n    left: 8px;\r\n    width: 80px;\r\n    bottom: 5px;\r\n    background-color: rgba(255,255,255,.2);\r\n} \r\n.MiEPRight {\r\n    position: relative;\r\n    top: 5px;\r\n    left: 93px;\r\n    right: 8px;\r\n    xbottom: 5px;\r\n    padding: 3px 5px;\r\n    color: white;\r\n    background-color: transparent;\r\n    font-family: calibri,arial;\r\n    font-size: 10pt;\r\n}\r\n.MiEPTabs {\r\n    list-style-type: none;\r\n    padding: 1px 3px;\r\n}   \r\n.MiEPTabs li {\r\n    color: white;\r\n    text-align: center;\r\n    -moz-border-radius-topleft: 3px:\r\n    -webkit-border-top-left-radius: 3px;\r\n    border-top-left-radius: 3px;\r\n    -moz-border-radius-bottomleft: 3px:\r\n    -webkit-border-bottom-left-radius: 3px;\r\n    border-bottom-left-radius: 3px;\r\n}\r\n.MiEPTabs li:hover {\r\n    background-color: rgba(200,200,100,.5);\r\n    cursor: default;\r\n}\r\n.MiEPTabOn {\r\n    color: #FFA;\r\n    background-color: rgba(173,216,230,.5);\r\n}\r\n        ');
    DomElement.addStyle(MinionsEdit.Classes.MiColorPicker.pickerCss);
})();
MiKeyMap._editKeys = null;
MiMask._mask1 = null;
MiMask._mask2 = null;
MiMask._sizer = null;
MiMask._pos = null;
MiMask._wd = 0;
MiMask._ht = 0;
MiMask._once = false;
MiMask._css = { position: 'absolute', border: '2px dotted #f444f4', color: 'transparent', 'background-color': 'transparent', margin: 0, padding: 0 };
MiMask._sizercss = { position: 'absolute', width: 10, height: 10, color: 'transparent', margin: 0, padding: 0, 'text-align': 'center', 'z-index': 1 };
(function () {
    MiMask._createMask();
})();
MiMetrics.minWidth = 20;
MiMetrics.minHeight = 20 / 2;
MinionEdit.gigMe = 'GigMe';
MinionEdit.dotGigMe = '.' + 'GigMe';
MinionEdit.minSize = 20;
MinionEdit.maskOnEv = 'MaskOnEv';
MinionEdit.maskOffEv = 'MaskOffEv';
MinionEdit.maskSleepEv = 'MaskSleepEv';
MinionEdit.maskWakeEv = 'MaskWakeEv';
MinionEdit.maskRubberbandEv = 'MaskRubberbandEv';
MinionEdit.uploadImgEv = 'UploadImgEv';
MinionEdit.pageManagerEv = 'PageManagerEv';
MinionEdit._activeFocus$4 = null;
MinionEdit.editKeys = null;
MinionEdit.maskSleeping = false;
(function () {
    Nsb.Classes.Evo.bind('MaskOnEv', new Nsb.Classes.Evo().fn(MiMask.maskOn));
    Nsb.Classes.Evo.bind('MaskOffEv', new Nsb.Classes.Evo().fn(MiMask.maskOff));
    Nsb.Classes.Evo.bind('MaskSleepEv', new Nsb.Classes.Evo().fn(MiMask.maskSleep));
    Nsb.Classes.Evo.bind('MaskWakeEv', new Nsb.Classes.Evo().fn(MiMask.maskWake));
    Nsb.Classes.Evo.bind('MaskRubberbandEv', new Nsb.Classes.Evo().fn(MiMask.maskRubberband));
    Nsb.Classes.Evo.bind('PageManagerEv', new Nsb.Classes.Evo().fn(MinionEdit.pagesEv));
    MiKeyMap.installEvents();
})();
MiPageGear._pageGearIsOn = false;
MinionPaste._reIds = null;
(function () {
    DomElement.addStyle('\r\n        .MiPopChoice {\r\n            width: 500px;\r\n        }\r\n        .MiPopChoice ul {\r\n            list-style-type: none;\r\n            padding: 0;\r\n            margin: 5px 10px;\r\n        }\r\n        .MiPopChoice a {\r\n            color: black;\r\n        }\r\n        .MiPopChoice a:active {\r\n            color: black;\r\n        }\r\n        .MiPopChoice a:visited {\r\n            color: black;\r\n        }\r\n        .MiPopChoice a:hover {\r\n            color: #666;\r\n            cursor: default;\r\n        }\r\n        ');
})();
MiUiOp._fromId = null;
MiUiOp.cancelled = false;
MiUiOp._e = null;
MiUiOp._ui = null;
MiUiOp._active = false;
MiUiOp._queRestore = false;
MiUiOp._onAbort = null;
MiUiOp._snapshot = null;
MinionsEdit.Classes.Pages._instance$3 = null;
(function () {
    DomElement.addStyle('\r\n        .TinyPopup {\r\n            position: absolute;\r\n            width: 200px;\r\n            background-color: rgba(255,255,255,.65);\r\n            border: 1px solid black;\r\n            -moz-border-radius: 4px;\r\n            -webkit-border-radius: 4px;\r\n            border-radius: 4px;\r\n        }\r\n        ');
})();
})();

//! This script was generated using Script# v0.7.4.0
